| 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 2472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2483 ASSERT_NE(-1, idx); | 2483 ASSERT_NE(-1, idx); |
| 2484 | 2484 |
| 2485 bluez::FakeBluetoothDeviceClient::Properties* properties = | 2485 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2486 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 2486 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2487 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); | 2487 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| 2488 | 2488 |
| 2489 // During discovery, rssi is a valid value (-75) | 2489 // During discovery, rssi is a valid value (-75) |
| 2490 properties->rssi.ReplaceValue(-75); | 2490 properties->rssi.ReplaceValue(-75); |
| 2491 properties->rssi.set_valid(true); | 2491 properties->rssi.set_valid(true); |
| 2492 | 2492 |
| 2493 ASSERT_EQ(-75, devices[idx]->GetInquiryRSSI()); | 2493 ASSERT_EQ(-75, devices[idx]->GetInquiryRSSI().value()); |
| 2494 |
| 2495 properties->rssi.ReplaceValue(INT8_MAX + 1); |
| 2496 ASSERT_EQ(INT8_MAX, devices[idx]->GetInquiryRSSI().value()); |
| 2497 |
| 2498 properties->rssi.ReplaceValue(INT8_MIN - 1); |
| 2499 ASSERT_EQ(INT8_MIN, devices[idx]->GetInquiryRSSI().value()); |
| 2494 | 2500 |
| 2495 // Install an observer; expect the DeviceChanged method to be called when | 2501 // Install an observer; expect the DeviceChanged method to be called when |
| 2496 // we invalidate the RSSI of the device. | 2502 // we invalidate the RSSI of the device. |
| 2497 TestBluetoothAdapterObserver observer(adapter_); | 2503 TestBluetoothAdapterObserver observer(adapter_); |
| 2498 | 2504 |
| 2499 // When discovery is over, the value should be invalidated. | 2505 // When discovery is over, the value should be invalidated. |
| 2500 properties->rssi.set_valid(false); | 2506 properties->rssi.set_valid(false); |
| 2501 properties->NotifyPropertyChanged(properties->rssi.name()); | 2507 properties->NotifyPropertyChanged(properties->rssi.name()); |
| 2502 | 2508 |
| 2503 EXPECT_EQ(1, observer.device_changed_count()); | 2509 EXPECT_EQ(1, observer.device_changed_count()); |
| 2504 EXPECT_EQ(devices[idx], observer.last_device()); | 2510 EXPECT_EQ(devices[idx], observer.last_device()); |
| 2505 | 2511 |
| 2506 int unknown_power = BluetoothDevice::kUnknownPower; | 2512 EXPECT_FALSE(devices[idx]->GetInquiryRSSI()); |
| 2507 EXPECT_EQ(unknown_power, devices[idx]->GetInquiryRSSI()); | |
| 2508 } | 2513 } |
| 2509 | 2514 |
| 2510 TEST_F(BluetoothBlueZTest, DeviceInquiryTxPowerInvalidated) { | 2515 TEST_F(BluetoothBlueZTest, DeviceInquiryTxPowerInvalidated) { |
| 2511 // Simulate invalidation of inquiry TxPower of a device, as it occurs | 2516 // Simulate invalidation of inquiry TxPower of a device, as it occurs |
| 2512 // when discovery is finished. | 2517 // when discovery is finished. |
| 2513 GetAdapter(); | 2518 GetAdapter(); |
| 2514 | 2519 |
| 2515 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2520 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 2516 ASSERT_EQ(2U, devices.size()); | 2521 ASSERT_EQ(2U, devices.size()); |
| 2517 | 2522 |
| 2518 int idx = GetDeviceIndexByAddress( | 2523 int idx = GetDeviceIndexByAddress( |
| 2519 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); | 2524 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 2520 ASSERT_NE(-1, idx); | 2525 ASSERT_NE(-1, idx); |
| 2521 | 2526 |
| 2522 bluez::FakeBluetoothDeviceClient::Properties* properties = | 2527 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 2523 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 2528 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 2524 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); | 2529 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| 2525 | 2530 |
| 2526 // During discovery, tx_power is a valid value (0) | 2531 // During discovery, tx_power is a valid value (0) |
| 2527 properties->tx_power.ReplaceValue(0); | 2532 properties->tx_power.ReplaceValue(0); |
| 2528 properties->tx_power.set_valid(true); | 2533 properties->tx_power.set_valid(true); |
| 2529 | 2534 |
| 2530 ASSERT_EQ(0, devices[idx]->GetInquiryTxPower()); | 2535 ASSERT_EQ(0, devices[idx]->GetInquiryTxPower().value()); |
| 2536 |
| 2537 properties->tx_power.ReplaceValue(INT8_MAX + 1); |
| 2538 ASSERT_EQ(INT8_MAX, devices[idx]->GetInquiryTxPower().value()); |
| 2539 |
| 2540 properties->tx_power.ReplaceValue(INT8_MIN - 1); |
| 2541 ASSERT_EQ(INT8_MIN, devices[idx]->GetInquiryTxPower().value()); |
| 2531 | 2542 |
| 2532 // Install an observer; expect the DeviceChanged method to be called when | 2543 // Install an observer; expect the DeviceChanged method to be called when |
| 2533 // we invalidate the tx_power of the device. | 2544 // we invalidate the tx_power of the device. |
| 2534 TestBluetoothAdapterObserver observer(adapter_); | 2545 TestBluetoothAdapterObserver observer(adapter_); |
| 2535 | 2546 |
| 2536 // When discovery is over, the value should be invalidated. | 2547 // When discovery is over, the value should be invalidated. |
| 2537 properties->tx_power.set_valid(false); | 2548 properties->tx_power.set_valid(false); |
| 2538 properties->NotifyPropertyChanged(properties->tx_power.name()); | 2549 properties->NotifyPropertyChanged(properties->tx_power.name()); |
| 2539 | 2550 |
| 2540 EXPECT_EQ(1, observer.device_changed_count()); | 2551 EXPECT_EQ(1, observer.device_changed_count()); |
| 2541 EXPECT_EQ(devices[idx], observer.last_device()); | 2552 EXPECT_EQ(devices[idx], observer.last_device()); |
| 2542 | 2553 |
| 2543 int unknown_power = BluetoothDevice::kUnknownPower; | 2554 EXPECT_FALSE(devices[idx]->GetInquiryTxPower()); |
| 2544 EXPECT_EQ(unknown_power, devices[idx]->GetInquiryTxPower()); | |
| 2545 } | 2555 } |
| 2546 | 2556 |
| 2547 TEST_F(BluetoothBlueZTest, ForgetDevice) { | 2557 TEST_F(BluetoothBlueZTest, ForgetDevice) { |
| 2548 GetAdapter(); | 2558 GetAdapter(); |
| 2549 | 2559 |
| 2550 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2560 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 2551 ASSERT_EQ(2U, devices.size()); | 2561 ASSERT_EQ(2U, devices.size()); |
| 2552 | 2562 |
| 2553 int idx = GetDeviceIndexByAddress( | 2563 int idx = GetDeviceIndexByAddress( |
| 2554 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); | 2564 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| (...skipping 1942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4497 adapter_->Shutdown(); | 4507 adapter_->Shutdown(); |
| 4498 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); | 4508 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); |
| 4499 | 4509 |
| 4500 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, | 4510 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, |
| 4501 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. | 4511 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. |
| 4502 EXPECT_EQ(0, callback_count_); | 4512 EXPECT_EQ(0, callback_count_); |
| 4503 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); | 4513 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); |
| 4504 } | 4514 } |
| 4505 | 4515 |
| 4506 } // namespace bluez | 4516 } // namespace bluez |
| OLD | NEW |