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

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

Issue 1260533003: BluetoothTest.* tests in bluetooth_device_unittests.cc run on Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@test2
Patch Set: Created 5 years, 4 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
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_low_energy_device_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/macros.h" 7 #include "base/macros.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" 10 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 #if defined(OS_ANDROID) 13 #if defined(OS_ANDROID)
14 #include "device/bluetooth/test/bluetooth_test_android.h" 14 #include "device/bluetooth/test/bluetooth_test_android.h"
15 #elif defined(OS_MACOSX)
16 #include "device/bluetooth/test/bluetooth_test_mac.h"
15 #endif 17 #endif
16 18
17 namespace device { 19 namespace device {
18 20
19 TEST(BluetoothDeviceTest, CanonicalizeAddressFormat_AcceptsAllValidFormats) { 21 TEST(BluetoothDeviceTest, CanonicalizeAddressFormat_AcceptsAllValidFormats) {
20 // There are three valid separators (':', '-', and none). 22 // There are three valid separators (':', '-', and none).
21 // Case shouldn't matter. 23 // Case shouldn't matter.
22 const char* const kValidFormats[] = { 24 const char* const kValidFormats[] = {
23 "1A:2B:3C:4D:5E:6F", 25 "1A:2B:3C:4D:5E:6F",
24 "1a:2B:3c:4D:5e:6F", 26 "1a:2B:3c:4D:5e:6F",
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 "1:A2:B3:C4:D5:E6F", 58 "1:A2:B3:C4:D5:E6F",
57 }; 59 };
58 60
59 for (size_t i = 0; i < arraysize(kValidFormats); ++i) { 61 for (size_t i = 0; i < arraysize(kValidFormats); ++i) {
60 SCOPED_TRACE(std::string("Input format: '") + kValidFormats[i] + "'"); 62 SCOPED_TRACE(std::string("Input format: '") + kValidFormats[i] + "'");
61 EXPECT_EQ(std::string(), 63 EXPECT_EQ(std::string(),
62 BluetoothDevice::CanonicalizeAddress(kValidFormats[i])); 64 BluetoothDevice::CanonicalizeAddress(kValidFormats[i]));
63 } 65 }
64 } 66 }
65 67
66 #if defined(OS_ANDROID) 68 #if defined(OS_ANDROID) || defined(OS_MACOSX)
67 // Verifies basic device properties, e.g. GetAddress, GetName, ... 69 // Verifies basic device properties, e.g. GetAddress, GetName, ...
68 TEST_F(BluetoothTest, DeviceProperties) { 70 TEST_F(BluetoothTest, LowEnergyDeviceProperties) {
71 if (!PlatformSupportsLowEnergy()) {
72 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
73 return;
74 }
69 InitWithFakeAdapter(); 75 InitWithFakeAdapter();
70 TestBluetoothAdapterObserver observer(adapter_); 76 TestBluetoothAdapterObserver observer(adapter_);
71 77
72 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), 78 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(),
73 GetErrorCallback()); 79 GetErrorCallback());
74 base::RunLoop().RunUntilIdle(); 80 base::RunLoop().RunUntilIdle();
75 DiscoverLowEnergyDevice(1); 81 DiscoverLowEnergyDevice(1);
76 base::RunLoop().RunUntilIdle(); 82 base::RunLoop().RunUntilIdle();
77 BluetoothDevice* device = observer.last_device(); 83 BluetoothDevice* device = observer.last_device();
78 ASSERT_TRUE(device); 84 ASSERT_TRUE(device);
79 EXPECT_EQ(0x1F00u, device->GetBluetoothClass()); 85 EXPECT_EQ(0x1F00u, device->GetBluetoothClass());
80 EXPECT_EQ(kTestDeviceAddress1, device->GetAddress()); 86 EXPECT_EQ(kTestDeviceAddress1, device->GetAddress());
81 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); 87 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource());
82 EXPECT_EQ(0, device->GetVendorID()); 88 EXPECT_EQ(0, device->GetVendorID());
83 EXPECT_EQ(0, device->GetProductID()); 89 EXPECT_EQ(0, device->GetProductID());
84 EXPECT_EQ(0, device->GetDeviceID()); 90 EXPECT_EQ(0, device->GetDeviceID());
85 EXPECT_EQ(base::UTF8ToUTF16("FakeBluetoothDevice"), device->GetName()); 91 EXPECT_EQ(base::UTF8ToUTF16(kTestDeviceName), device->GetName());
86 EXPECT_EQ(true, device->IsPaired()); 92 EXPECT_FALSE(device->IsPaired());
87 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); 93 BluetoothDevice::UUIDList uuids = device->GetUUIDs();
88 EXPECT_TRUE(ContainsValue(uuids, BluetoothUUID("1800"))); 94 EXPECT_TRUE(ContainsValue(uuids, BluetoothUUID(kTestUUIDGenericAccess)));
89 EXPECT_TRUE(ContainsValue(uuids, BluetoothUUID("1801"))); 95 EXPECT_TRUE(ContainsValue(uuids, BluetoothUUID(kTestUUIDGenericAttribute)));
90 } 96 }
91 #endif // defined(OS_ANDROID) 97 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
92 98
93 #if defined(OS_ANDROID) 99 #if defined(OS_ANDROID) || defined(OS_MACOSX)
94 // Device with no advertised Service UUIDs. 100 // Device with no advertised Service UUIDs.
95 TEST_F(BluetoothTest, DeviceNoUUIDs) { 101 TEST_F(BluetoothTest, LowEnergyDeviceNoUUIDs) {
102 if (!PlatformSupportsLowEnergy()) {
103 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
104 return;
105 }
96 InitWithFakeAdapter(); 106 InitWithFakeAdapter();
97 TestBluetoothAdapterObserver observer(adapter_); 107 TestBluetoothAdapterObserver observer(adapter_);
98 108
99 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), 109 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(),
100 GetErrorCallback()); 110 GetErrorCallback());
101 base::RunLoop().RunUntilIdle(); 111 base::RunLoop().RunUntilIdle();
102 DiscoverLowEnergyDevice(3); 112 DiscoverLowEnergyDevice(3);
103 base::RunLoop().RunUntilIdle(); 113 base::RunLoop().RunUntilIdle();
104 BluetoothDevice* device = observer.last_device(); 114 BluetoothDevice* device = observer.last_device();
105 ASSERT_TRUE(device); 115 ASSERT_TRUE(device);
106 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); 116 BluetoothDevice::UUIDList uuids = device->GetUUIDs();
107 EXPECT_EQ(0u, uuids.size()); 117 EXPECT_EQ(0u, uuids.size());
108 } 118 }
109 #endif // defined(OS_ANDROID) 119 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
110 120
111 // TODO(scheib): Test with a device with no name. http://crbug.com/506415 121 // TODO(scheib): Test with a device with no name. http://crbug.com/506415
112 // BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() will run, which 122 // BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() will run, which
113 // requires string resources to be loaded. For that, something like 123 // requires string resources to be loaded. For that, something like
114 // InitSharedInstance must be run. See unittest files that call that. It will 124 // InitSharedInstance must be run. See unittest files that call that. It will
115 // also require build configuration to generate string resources into a .pak 125 // also require build configuration to generate string resources into a .pak
116 // file. 126 // file.
117 127
118 } // namespace device 128 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_low_energy_device_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698