OLD | NEW |
---|---|
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 |
(...skipping 2485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2496 // we invalidate the RSSI of the device. | 2496 // we invalidate the RSSI of the device. |
2497 TestBluetoothAdapterObserver observer(adapter_); | 2497 TestBluetoothAdapterObserver observer(adapter_); |
2498 | 2498 |
2499 // When discovery is over, the value should be invalidated. | 2499 // When discovery is over, the value should be invalidated. |
2500 properties->rssi.set_valid(false); | 2500 properties->rssi.set_valid(false); |
2501 properties->NotifyPropertyChanged(properties->rssi.name()); | 2501 properties->NotifyPropertyChanged(properties->rssi.name()); |
2502 | 2502 |
2503 EXPECT_EQ(1, observer.device_changed_count()); | 2503 EXPECT_EQ(1, observer.device_changed_count()); |
2504 EXPECT_EQ(devices[idx], observer.last_device()); | 2504 EXPECT_EQ(devices[idx], observer.last_device()); |
2505 | 2505 |
2506 int unknown_power = BluetoothDevice::kUnknownPower; | 2506 EXPECT_TRUE(devices[idx]->GetInquiryRSSI() == BluetoothDevice::kUnknownRSSI); |
2507 EXPECT_EQ(unknown_power, devices[idx]->GetInquiryRSSI()); | 2507 } |
2508 | |
2509 TEST_F(BluetoothBlueZTest, DeviceInquiryRSSIOutOfBounds) { | |
2510 // RSSI should be a int8 but luez returns a int16 because DBus doesn't | |
scheib
2016/05/04 01:18:37
bluez
^
ortuno
2016/05/04 16:44:11
Done.
| |
2511 // support int8 even though Bluez uses a int8 internally. This test | |
2512 // makes sure we handle values outside of the int8 range. | |
2513 GetAdapter(); | |
2514 | |
2515 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | |
2516 ASSERT_EQ(2U, devices.size()); | |
2517 | |
2518 int idx = GetDeviceIndexByAddress( | |
2519 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); | |
2520 ASSERT_NE(-1, idx); | |
2521 | |
2522 bluez::FakeBluetoothDeviceClient::Properties* properties = | |
2523 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | |
2524 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); | |
2525 | |
2526 properties->rssi.set_valid(true); | |
2527 | |
2528 // Small invalid value | |
2529 properties->rssi.ReplaceValue(-129); | |
2530 EXPECT_TRUE(devices[idx]->GetInquiryRSSI() == BluetoothDevice::kUnknownRSSI); | |
2531 | |
2532 // Small valid value | |
2533 properties->rssi.ReplaceValue(-128); | |
2534 EXPECT_EQ(-128, devices[idx]->GetInquiryRSSI()); | |
2535 | |
2536 // Large valid value. (127 is used for BluetoothDevice::kUnknownRSSI). | |
2537 properties->rssi.ReplaceValue(126); | |
2538 EXPECT_EQ(126, devices[idx]->GetInquiryRSSI()); | |
2539 | |
2540 // Large invalid value | |
2541 properties->rssi.ReplaceValue(128); | |
2542 EXPECT_TRUE(devices[idx]->GetInquiryRSSI() == BluetoothDevice::kUnknownRSSI); | |
scheib
2016/05/04 01:18:37
EXPECT_EQ instead of _TRUE. (and elsewhere)
ortuno
2016/05/04 16:44:12
That's what I tried to do the first time but I get
| |
2508 } | 2543 } |
2509 | 2544 |
2510 TEST_F(BluetoothBlueZTest, DeviceInquiryTxPowerInvalidated) { | 2545 TEST_F(BluetoothBlueZTest, DeviceInquiryTxPowerInvalidated) { |
2511 // Simulate invalidation of inquiry TxPower of a device, as it occurs | 2546 // Simulate invalidation of inquiry TxPower of a device, as it occurs |
2512 // when discovery is finished. | 2547 // when discovery is finished. |
2513 GetAdapter(); | 2548 GetAdapter(); |
2514 | 2549 |
2515 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2550 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
2516 ASSERT_EQ(2U, devices.size()); | 2551 ASSERT_EQ(2U, devices.size()); |
2517 | 2552 |
(...skipping 15 matching lines...) Expand all Loading... | |
2533 // we invalidate the tx_power of the device. | 2568 // we invalidate the tx_power of the device. |
2534 TestBluetoothAdapterObserver observer(adapter_); | 2569 TestBluetoothAdapterObserver observer(adapter_); |
2535 | 2570 |
2536 // When discovery is over, the value should be invalidated. | 2571 // When discovery is over, the value should be invalidated. |
2537 properties->tx_power.set_valid(false); | 2572 properties->tx_power.set_valid(false); |
2538 properties->NotifyPropertyChanged(properties->tx_power.name()); | 2573 properties->NotifyPropertyChanged(properties->tx_power.name()); |
2539 | 2574 |
2540 EXPECT_EQ(1, observer.device_changed_count()); | 2575 EXPECT_EQ(1, observer.device_changed_count()); |
2541 EXPECT_EQ(devices[idx], observer.last_device()); | 2576 EXPECT_EQ(devices[idx], observer.last_device()); |
2542 | 2577 |
2543 int unknown_power = BluetoothDevice::kUnknownPower; | 2578 EXPECT_TRUE(devices[idx]->GetInquiryTxPower() == |
2544 EXPECT_EQ(unknown_power, devices[idx]->GetInquiryTxPower()); | 2579 BluetoothDevice::kUnknownTxPower); |
2580 } | |
2581 | |
2582 TEST_F(BluetoothBlueZTest, DeviceInquiryTxPowerOutOfBounds) { | |
2583 // TxPower should be a int8 but Bluez returns a int16 because DBus doesn't | |
2584 // support int8 even though Bluez uses a int8 internally. This test | |
2585 // makes sure we handle values outside of the int8 range. | |
2586 GetAdapter(); | |
2587 | |
2588 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | |
2589 ASSERT_EQ(2U, devices.size()); | |
2590 | |
2591 int idx = GetDeviceIndexByAddress( | |
2592 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); | |
2593 ASSERT_NE(-1, idx); | |
2594 | |
2595 bluez::FakeBluetoothDeviceClient::Properties* properties = | |
2596 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | |
2597 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); | |
2598 | |
2599 properties->tx_power.set_valid(true); | |
2600 | |
2601 // Small invalid value | |
2602 properties->tx_power.ReplaceValue(-129); | |
2603 EXPECT_TRUE(devices[idx]->GetInquiryTxPower() == | |
2604 BluetoothDevice::kUnknownTxPower); | |
2605 | |
2606 // Small valid value | |
2607 properties->tx_power.ReplaceValue(-128); | |
2608 EXPECT_EQ(-128, devices[idx]->GetInquiryTxPower()); | |
2609 | |
2610 // Large valid value. (127 is used for BluetoothDevice::kUnknownTxPower). | |
scheib
2016/05/04 01:18:37
What does Bluez use for UnknownTxPower? This patch
ortuno
2016/05/04 16:44:12
In bluez, if a property is not present property.is
| |
2611 properties->tx_power.ReplaceValue(126); | |
2612 EXPECT_EQ(126, devices[idx]->GetInquiryTxPower()); | |
2613 | |
2614 // Large invalid value | |
2615 properties->tx_power.ReplaceValue(128); | |
2616 EXPECT_TRUE(devices[idx]->GetInquiryTxPower() == | |
2617 BluetoothDevice::kUnknownTxPower); | |
2545 } | 2618 } |
2546 | 2619 |
2547 TEST_F(BluetoothBlueZTest, ForgetDevice) { | 2620 TEST_F(BluetoothBlueZTest, ForgetDevice) { |
2548 GetAdapter(); | 2621 GetAdapter(); |
2549 | 2622 |
2550 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2623 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
2551 ASSERT_EQ(2U, devices.size()); | 2624 ASSERT_EQ(2U, devices.size()); |
2552 | 2625 |
2553 int idx = GetDeviceIndexByAddress( | 2626 int idx = GetDeviceIndexByAddress( |
2554 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); | 2627 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
(...skipping 1570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4125 EXPECT_EQ(0, device->GetProductID()); | 4198 EXPECT_EQ(0, device->GetProductID()); |
4126 EXPECT_EQ(0, device->GetDeviceID()); | 4199 EXPECT_EQ(0, device->GetDeviceID()); |
4127 } | 4200 } |
4128 | 4201 |
4129 TEST_F(BluetoothBlueZTest, GetConnectionInfoForDisconnectedDevice) { | 4202 TEST_F(BluetoothBlueZTest, GetConnectionInfoForDisconnectedDevice) { |
4130 GetAdapter(); | 4203 GetAdapter(); |
4131 BluetoothDevice* device = adapter_->GetDevice( | 4204 BluetoothDevice* device = adapter_->GetDevice( |
4132 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); | 4205 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
4133 | 4206 |
4134 // Calling GetConnectionInfo for an unconnected device should return a result | 4207 // Calling GetConnectionInfo for an unconnected device should return a result |
4135 // in which all fields are filled with BluetoothDevice::kUnknownPower. | 4208 // in which all fields are filled with BluetoothDevice::kUnknownRSSI and |
4209 // BluetoothDevice::kUnknownTxPower. | |
4136 BluetoothDevice::ConnectionInfo conn_info(0, 0, 0); | 4210 BluetoothDevice::ConnectionInfo conn_info(0, 0, 0); |
4137 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); | 4211 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); |
4138 int unknown_power = BluetoothDevice::kUnknownPower; | 4212 |
4139 EXPECT_NE(0, unknown_power); | 4213 EXPECT_TRUE(conn_info.rssi == BluetoothDevice::kUnknownRSSI); |
4140 EXPECT_EQ(unknown_power, conn_info.rssi); | 4214 EXPECT_TRUE(conn_info.transmit_power == BluetoothDevice::kUnknownTxPower); |
4141 EXPECT_EQ(unknown_power, conn_info.transmit_power); | 4215 EXPECT_TRUE(conn_info.max_transmit_power == BluetoothDevice::kUnknownTxPower); |
4142 EXPECT_EQ(unknown_power, conn_info.max_transmit_power); | |
4143 } | 4216 } |
4144 | 4217 |
4145 TEST_F(BluetoothBlueZTest, GetConnectionInfoForConnectedDevice) { | 4218 TEST_F(BluetoothBlueZTest, GetConnectionInfoForConnectedDevice) { |
4146 GetAdapter(); | 4219 GetAdapter(); |
4147 BluetoothDevice* device = adapter_->GetDevice( | 4220 BluetoothDevice* device = adapter_->GetDevice( |
4148 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); | 4221 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
4149 | 4222 |
4150 device->Connect(nullptr, GetCallback(), | 4223 device->Connect(nullptr, GetCallback(), |
4151 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, | 4224 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback, |
4152 base::Unretained(this))); | 4225 base::Unretained(this))); |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4481 adapter_->Shutdown(); | 4554 adapter_->Shutdown(); |
4482 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); | 4555 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); |
4483 | 4556 |
4484 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, | 4557 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, |
4485 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. | 4558 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. |
4486 EXPECT_EQ(0, callback_count_); | 4559 EXPECT_EQ(0, callback_count_); |
4487 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); | 4560 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); |
4488 } | 4561 } |
4489 | 4562 |
4490 } // namespace bluez | 4563 } // namespace bluez |
OLD | NEW |