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

Unified Diff: device/bluetooth/bluez/bluetooth_service_record_bluez_unittest.cc

Issue 2102093003: Implement BluetoothDeviceBlueZ::GetServiceRecords. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluez/bluetooth_service_record_bluez_unittest.cc
diff --git a/device/bluetooth/bluez/bluetooth_service_record_bluez_unittest.cc b/device/bluetooth/bluez/bluetooth_service_record_bluez_unittest.cc
index 639f3c56ba5b3b92f663e31c721e993db71f7203..4c9afbd8b121672ac445b3b08d3065b2d66a786e 100644
--- a/device/bluetooth/bluez/bluetooth_service_record_bluez_unittest.cc
+++ b/device/bluetooth/bluez/bluetooth_service_record_bluez_unittest.cc
@@ -14,7 +14,10 @@
#include "base/run_loop.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/bluez/bluetooth_adapter_bluez.h"
+#include "device/bluetooth/bluez/bluetooth_device_bluez.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
+#include "device/bluetooth/dbus/fake_bluetooth_device_client.h"
+#include "device/bluetooth/test/bluetooth_test_bluez.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace bluez {
@@ -27,30 +30,48 @@ constexpr char kServiceUuid1[] = "00001801-0000-1000-8000-00805f9b34fb";
constexpr char kServiceUuid2[] = "00001801-0000-1000-7000-00805f9b34fb";
constexpr char kServiceUuid3[] = "00001801-0000-1000-3000-00805f9b34fb";
+class TestPairingDelegate : public device::BluetoothDevice::PairingDelegate {
+ public:
+ void RequestPinCode(device::BluetoothDevice* device) override {
+ LOG(ERROR) << "RKC: 1";
xiyuan 2016/06/29 22:43:08 remove debugging log, here and other places?
rkc 2016/06/30 20:02:24 Whoops. Done.
+ }
+ void RequestPasskey(device::BluetoothDevice* device) override {
+ LOG(ERROR) << "RKC: 2";
+ }
+ void DisplayPinCode(device::BluetoothDevice* device,
+ const std::string& pincode) override {
+ LOG(ERROR) << "RKC: 3";
+ }
+ void DisplayPasskey(device::BluetoothDevice* device,
+ uint32_t passkey) override {
+ LOG(ERROR) << "RKC: 4";
+ }
+ void KeysEntered(device::BluetoothDevice* device, uint32_t entered) override {
+ LOG(ERROR) << "RKC: 5";
+ }
+ void ConfirmPasskey(device::BluetoothDevice* device,
+ uint32_t passkey) override {
+ LOG(ERROR) << "RKC: 6";
+ }
+ void AuthorizePairing(device::BluetoothDevice* device) override {
+ LOG(ERROR) << "RKC: 7";
+ }
+};
+
} // namespace
-class BluetoothServiceRecordBlueZTest : public testing::Test {
+class BluetoothServiceRecordBlueZTest : public device::BluetoothTestBlueZ {
public:
BluetoothServiceRecordBlueZTest()
: adapter_bluez_(nullptr),
success_callbacks_(0),
error_callbacks_(0),
- run_loop_(nullptr),
last_seen_handle_(0) {}
void SetUp() override {
- std::unique_ptr<bluez::BluezDBusManagerSetter> dbus_setter =
- bluez::BluezDBusManager::GetSetterForTesting();
-
- device::BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothServiceRecordBlueZTest::AdapterCallback,
- base::Unretained(this)));
- RunRunLoop();
- }
-
- void TearDown() override {
- device::BluetoothAdapterFactory::Shutdown();
- bluez::BluezDBusManager::Shutdown();
+ BluetoothTestBlueZ::SetUp();
+ InitWithFakeAdapter();
+ adapter_bluez_ = static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get());
}
uint32_t CreateServiceRecordWithCallbacks(
@@ -89,39 +110,63 @@ class BluetoothServiceRecordBlueZTest : public testing::Test {
EXPECT_EQ(old_error_callbacks + 1 - success, error_callbacks_);
}
+ void GetServiceRecords(BluetoothDeviceBlueZ* device, bool expect_success) {
+ const size_t old_success_callbacks = success_callbacks_;
+ const size_t old_error_callbacks = error_callbacks_;
+ records_.clear();
+ device->GetServiceRecords(
+ base::Bind(&BluetoothServiceRecordBlueZTest::GetServiceRecordsCallback,
+ base::Unretained(this)),
+ base::Bind(&BluetoothServiceRecordBlueZTest::ErrorCallback,
+ base::Unretained(this)));
+ size_t success = expect_success ? 1 : 0;
Miao 2016/06/30 04:55:59 Instead of passing an extra |bool expect_success|
rkc 2016/06/30 20:02:24 I expect us to have more tests :)
+ EXPECT_EQ(old_success_callbacks + success, success_callbacks_);
+ EXPECT_EQ(old_error_callbacks + 1 - success, error_callbacks_);
+ }
+
+ void VerifyRecords() {
+ EXPECT_EQ(2u, records_.size());
+
+ std::vector<uint16_t> ids0 = records_[0].GetAttributeIds();
+ EXPECT_EQ(2u, ids0.size());
+
+ BluetoothServiceAttributeValueBlueZ service_handle0 =
+ records_[0].GetAttributeValue(ids0[0]);
+ int32_t int_value;
+ EXPECT_TRUE(service_handle0.value().GetAsInteger(&int_value));
+ EXPECT_EQ(0x1337, int_value);
+
+ BluetoothServiceAttributeValueBlueZ service_class_list =
+ records_[0].GetAttributeValue(ids0[1]);
+ std::string str_value;
+ EXPECT_TRUE(
+ service_class_list.sequence()[0].value().GetAsString(&str_value));
+ EXPECT_EQ("1802", str_value);
+
+ std::vector<uint16_t> ids1 = records_[1].GetAttributeIds();
+ EXPECT_EQ(1u, ids1.size());
+
+ BluetoothServiceAttributeValueBlueZ service_handle1 =
+ records_[1].GetAttributeValue(ids1[0]);
+ EXPECT_TRUE(service_handle1.value().GetAsInteger(&int_value));
+ EXPECT_EQ(0xffffffff, static_cast<uint32_t>(int_value));
+ }
+
protected:
BluetoothServiceRecordBlueZ CreateaServiceRecord(const std::string uuid) {
- std::map<uint16_t, BluetoothServiceAttributeValueBlueZ> attributes;
- attributes.insert(std::pair<uint16_t, BluetoothServiceAttributeValueBlueZ>(
- kServiceUuidAttributeId,
- BluetoothServiceAttributeValueBlueZ(
- BluetoothServiceAttributeValueBlueZ::UUID, 16,
- base::MakeUnique<base::StringValue>(uuid))));
- return BluetoothServiceRecordBlueZ(attributes);
+ BluetoothServiceRecordBlueZ record;
+ record.AddRecordEntry(kServiceUuidAttributeId,
+ BluetoothServiceAttributeValueBlueZ(
+ BluetoothServiceAttributeValueBlueZ::UUID, 16,
+ base::MakeUnique<base::StringValue>(uuid)));
+ return record;
}
- scoped_refptr<device::BluetoothAdapter> adapter_;
BluetoothAdapterBlueZ* adapter_bluez_;
size_t success_callbacks_;
size_t error_callbacks_;
private:
- void RunRunLoop() {
- run_loop_ = base::MakeUnique<base::RunLoop>();
- run_loop_->Run();
- }
-
- void QuitRunLoop() {
- if (run_loop_)
- run_loop_->Quit();
- }
-
- void AdapterCallback(scoped_refptr<device::BluetoothAdapter> adapter) {
- adapter_ = adapter;
- adapter_bluez_ = static_cast<BluetoothAdapterBlueZ*>(adapter_.get());
- QuitRunLoop();
- }
-
void CreateServiceSuccessCallback(uint32_t handle) {
last_seen_handle_ = handle;
++success_callbacks_;
@@ -133,9 +178,14 @@ class BluetoothServiceRecordBlueZTest : public testing::Test {
++error_callbacks_;
}
- base::MessageLoop message_loop_;
- std::unique_ptr<base::RunLoop> run_loop_;
+ void GetServiceRecordsCallback(
+ std::vector<BluetoothServiceRecordBlueZ> records) {
+ records_ = records;
+ ++success_callbacks_;
+ }
+
uint32_t last_seen_handle_;
+ std::vector<BluetoothServiceRecordBlueZ> records_;
DISALLOW_COPY_AND_ASSIGN(BluetoothServiceRecordBlueZTest);
};
@@ -157,4 +207,15 @@ TEST_F(BluetoothServiceRecordBlueZTest, CreateAndRemove) {
RemoveServiceRecordWithCallbacks(handle2, true);
}
+TEST_F(BluetoothServiceRecordBlueZTest, GetServiceRecords) {
+ BluetoothDeviceBlueZ* device =
+ static_cast<BluetoothDeviceBlueZ*>(adapter_->GetDevice(
+ bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress));
+ GetServiceRecords(device, false);
+ device->Connect(nullptr, GetCallback(Call::EXPECTED),
+ GetConnectErrorCallback(Call::NOT_EXPECTED));
+ GetServiceRecords(device, true);
+ VerifyRecords();
+}
+
} // namespace bluez

Powered by Google App Engine
This is Rietveld 408576698