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

Side by Side Diff: device/bluetooth/bluez/bluetooth_bluez_unittest.cc

Issue 2369423003: bluetooth: Expose service data from BlueZ (Closed)
Patch Set: fix typo Created 4 years, 2 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 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 4468 matching lines...) Expand 10 before | Expand all | Expand 10 after
4479 } 4479 }
4480 adapter_->Shutdown(); 4480 adapter_->Shutdown();
4481 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); 4481 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", "");
4482 4482
4483 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, 4483 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError,
4484 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. 4484 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession.
4485 EXPECT_EQ(0, callback_count_); 4485 EXPECT_EQ(0, callback_count_);
4486 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); 4486 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_);
4487 } 4487 }
4488 4488
4489 TEST_F(BluetoothBlueZTest, ServiceDataChanged) {
4490 // Simulate a change of service data of a device.
4491 GetAdapter();
4492
4493 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
ortuno 2016/10/05 06:27:09 Just save a pointer to the device: BluetoothDevic
puthik_chromium 2016/10/06 01:49:56 Done.
4494 ASSERT_EQ(2U, devices.size());
4495
4496 int idx = GetDeviceIndexByAddress(
4497 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
4498 ASSERT_NE(-1, idx);
4499 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
4500 devices[idx]->GetAddress());
4501 ASSERT_EQ(
4502 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceAlias),
4503 devices[idx]->GetNameForDisplay());
4504
4505 // Install an observer; expect the DeviceChanged method to be called
4506 // when we change the service data.
4507 TestBluetoothAdapterObserver observer(adapter_);
4508
4509 bluez::FakeBluetoothDeviceClient::Properties* properties =
4510 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
4511 bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
4512
4513 static BluetoothUUID kUuid("1f08");
ortuno 2016/10/05 06:27:09 nit: Can you use kGapUuid?
puthik_chromium 2016/10/06 01:49:56 Sure
4514 static std::vector<uint8_t> kData = {1, 2, 3, 4, 5};
4515 std::unordered_map<std::string, std::vector<uint8_t>> service_data;
ortuno 2016/10/05 06:27:09 You could do: std::unordered_map<std::string, std
puthik_chromium 2016/10/06 01:49:56 Done.
4516 service_data[kUuid.canonical_value()] = kData;
4517
4518 properties->service_data.set_valid(true);
4519 properties->service_data.ReplaceValue(service_data);
ortuno 2016/10/05 06:27:10 Could you make this test a bit more thorough? i.e.
puthik_chromium 2016/10/06 01:49:56 Done.
4520
4521 EXPECT_EQ(1, observer.device_changed_count());
4522 EXPECT_EQ(devices[idx], observer.last_device());
4523
4524 BluetoothDevice::UUIDSet uuids = devices[idx]->GetServiceDataUUIDs();
ortuno 2016/10/05 06:27:09 Also test GetServiceData. You can use initializer
puthik_chromium 2016/10/06 01:49:56 Done.
puthik_chromium 2016/10/06 01:49:56 Done.
4525 EXPECT_EQ(1u, uuids.size());
4526 EXPECT_EQ(kUuid.canonical_value(), uuids.begin()->canonical_value());
ortuno 2016/10/05 06:27:09 Using initializer lists will make testing easier a
puthik_chromium 2016/10/06 01:49:56 Done
4527 const std::vector<uint8_t>* data = devices[idx]->GetServiceDataForUUID(kUuid);
4528 EXPECT_EQ(kData.size(), data->size());
4529 for (size_t i = 0; i < kData.size(); i++)
4530 EXPECT_EQ(kData[i], (*data)[i]);
ortuno 2016/10/05 06:27:10 Same here: EXPECT_EQ({1, 2, 3}, *GetServiceDataFo
puthik_chromium 2016/10/06 01:49:56 Done
4531 }
4532
4489 } // namespace bluez 4533 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698