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 4532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4543 BluetoothDevice::ServiceDataMap({{BluetoothUUID(kPnpUuid), {3, 2, 1}}}), | 4543 BluetoothDevice::ServiceDataMap({{BluetoothUUID(kPnpUuid), {3, 2, 1}}}), |
4544 device->GetServiceData()); | 4544 device->GetServiceData()); |
4545 EXPECT_EQ(BluetoothDevice::UUIDSet({BluetoothUUID(kPnpUuid)}), | 4545 EXPECT_EQ(BluetoothDevice::UUIDSet({BluetoothUUID(kPnpUuid)}), |
4546 device->GetServiceDataUUIDs()); | 4546 device->GetServiceDataUUIDs()); |
4547 EXPECT_EQ(std::vector<uint8_t>({3, 2, 1}), | 4547 EXPECT_EQ(std::vector<uint8_t>({3, 2, 1}), |
4548 *(device->GetServiceDataForUUID(BluetoothUUID(kPnpUuid)))); | 4548 *(device->GetServiceDataForUUID(BluetoothUUID(kPnpUuid)))); |
4549 EXPECT_EQ(nullptr, device->GetServiceDataForUUID(BluetoothUUID(kGapUuid))); | 4549 EXPECT_EQ(nullptr, device->GetServiceDataForUUID(BluetoothUUID(kGapUuid))); |
4550 EXPECT_EQ(nullptr, device->GetServiceDataForUUID(BluetoothUUID(kGattUuid))); | 4550 EXPECT_EQ(nullptr, device->GetServiceDataForUUID(BluetoothUUID(kGattUuid))); |
4551 } | 4551 } |
4552 | 4552 |
| 4553 TEST_F(BluetoothBlueZTest, ManufacturerDataChanged) { |
| 4554 const BluetoothDevice::ManufacturerId kManufacturerId1 = 0x1234; |
| 4555 const BluetoothDevice::ManufacturerId kManufacturerId2 = 0x2345; |
| 4556 const BluetoothDevice::ManufacturerId kManufacturerId3 = 0x3456; |
| 4557 |
| 4558 // Simulate a change of manufacturer data of a device. |
| 4559 GetAdapter(); |
| 4560 |
| 4561 BluetoothDevice* device = adapter_->GetDevice( |
| 4562 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 4563 |
| 4564 // Install an observer; expect the DeviceChanged method to be called |
| 4565 // when we change the service data. |
| 4566 TestBluetoothAdapterObserver observer(adapter_); |
| 4567 |
| 4568 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 4569 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 4570 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| 4571 |
| 4572 properties->manufacturer_data.set_valid(true); |
| 4573 |
| 4574 // Check that ManufacturerDataChanged is correctly invoke. |
| 4575 properties->manufacturer_data.ReplaceValue({{kManufacturerId1, {1, 2, 3}}}); |
| 4576 EXPECT_EQ(1, observer.device_changed_count()); |
| 4577 EXPECT_EQ(device, observer.last_device()); |
| 4578 EXPECT_EQ( |
| 4579 BluetoothDevice::ManufacturerDataMap({{kManufacturerId1, {1, 2, 3}}}), |
| 4580 device->GetManufacturerData()); |
| 4581 EXPECT_EQ(BluetoothDevice::ManufacturerIDSet({kManufacturerId1}), |
| 4582 device->GetManufacturerDataIDs()); |
| 4583 EXPECT_EQ(std::vector<uint8_t>({1, 2, 3}), |
| 4584 *(device->GetManufacturerDataForID(kManufacturerId1))); |
| 4585 |
| 4586 // Check that we can update service data with same uuid / add more uuid. |
| 4587 properties->manufacturer_data.ReplaceValue( |
| 4588 {{kManufacturerId1, {3, 2, 1}}, {kManufacturerId2, {1}}}); |
| 4589 EXPECT_EQ(2, observer.device_changed_count()); |
| 4590 EXPECT_EQ(device, observer.last_device()); |
| 4591 |
| 4592 EXPECT_EQ(BluetoothDevice::ManufacturerDataMap( |
| 4593 {{kManufacturerId1, {3, 2, 1}}, {kManufacturerId2, {1}}}), |
| 4594 device->GetManufacturerData()); |
| 4595 EXPECT_EQ( |
| 4596 BluetoothDevice::ManufacturerIDSet({kManufacturerId1, kManufacturerId2}), |
| 4597 device->GetManufacturerDataIDs()); |
| 4598 EXPECT_EQ(std::vector<uint8_t>({3, 2, 1}), |
| 4599 *(device->GetManufacturerDataForID(kManufacturerId1))); |
| 4600 EXPECT_EQ(std::vector<uint8_t>({1}), |
| 4601 *(device->GetManufacturerDataForID(kManufacturerId2))); |
| 4602 |
| 4603 // Check that we can remove uuid / change uuid with same data. |
| 4604 properties->manufacturer_data.ReplaceValue({{kManufacturerId3, {3, 2, 1}}}); |
| 4605 EXPECT_EQ(3, observer.device_changed_count()); |
| 4606 EXPECT_EQ(device, observer.last_device()); |
| 4607 |
| 4608 EXPECT_EQ( |
| 4609 BluetoothDevice::ManufacturerDataMap({{kManufacturerId3, {3, 2, 1}}}), |
| 4610 device->GetManufacturerData()); |
| 4611 EXPECT_EQ(BluetoothDevice::ManufacturerIDSet({kManufacturerId3}), |
| 4612 device->GetManufacturerDataIDs()); |
| 4613 EXPECT_EQ(std::vector<uint8_t>({3, 2, 1}), |
| 4614 *(device->GetManufacturerDataForID(kManufacturerId3))); |
| 4615 EXPECT_EQ(nullptr, device->GetManufacturerDataForID(kManufacturerId1)); |
| 4616 EXPECT_EQ(nullptr, device->GetManufacturerDataForID(kManufacturerId2)); |
| 4617 } |
| 4618 |
| 4619 TEST_F(BluetoothBlueZTest, AdvertisingDataFlagsChanged) { |
| 4620 // Simulate a change of advertising data flags of a device. |
| 4621 GetAdapter(); |
| 4622 |
| 4623 BluetoothDevice* device = adapter_->GetDevice( |
| 4624 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 4625 |
| 4626 // Install an observer; expect the DeviceChanged method to be called |
| 4627 // when we change the service data. |
| 4628 TestBluetoothAdapterObserver observer(adapter_); |
| 4629 |
| 4630 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 4631 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 4632 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| 4633 |
| 4634 properties->advertising_data_flags.set_valid(true); |
| 4635 |
| 4636 // Check that AdvertisingDataFlagsChanged is correctly invoke. |
| 4637 properties->advertising_data_flags.ReplaceValue(std::vector<uint8_t>({0x12})); |
| 4638 EXPECT_EQ(1, observer.device_changed_count()); |
| 4639 EXPECT_EQ(device, observer.last_device()); |
| 4640 EXPECT_TRUE(device->GetAdvertisingDataFlags().has_value()); |
| 4641 EXPECT_EQ(0x12u, device->GetAdvertisingDataFlags().value()); |
| 4642 |
| 4643 // Check that we can update advertising data flags. |
| 4644 properties->advertising_data_flags.ReplaceValue(std::vector<uint8_t>({0x23})); |
| 4645 EXPECT_EQ(2, observer.device_changed_count()); |
| 4646 EXPECT_EQ(device, observer.last_device()); |
| 4647 EXPECT_TRUE(device->GetAdvertisingDataFlags().has_value()); |
| 4648 EXPECT_EQ(0x23u, device->GetAdvertisingDataFlags().value()); |
| 4649 } |
| 4650 |
4553 } // namespace bluez | 4651 } // namespace bluez |
OLD | NEW |