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

Side by Side Diff: device/bluetooth/dbus/bluetooth_gatt_application_service_provider_unittest.cc

Issue 2254833003: Re-write many calls to WrapUnique() with MakeUnique() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "dbus/bus.h" 10 #include "dbus/bus.h"
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } // namespace 286 } // namespace
287 287
288 class BluetoothGattApplicationServiceProviderTest : public testing::Test { 288 class BluetoothGattApplicationServiceProviderTest : public testing::Test {
289 public: 289 public:
290 std::string CreateFakeService( 290 std::string CreateFakeService(
291 BluetoothGattApplicationServiceProviderImpl* app_provider, 291 BluetoothGattApplicationServiceProviderImpl* app_provider,
292 const std::string& service_path) { 292 const std::string& service_path) {
293 const std::string& full_service_path = 293 const std::string& full_service_path =
294 std::string(kAppObjectPath) + "/" + service_path; 294 std::string(kAppObjectPath) + "/" + service_path;
295 app_provider->service_providers_.push_back( 295 app_provider->service_providers_.push_back(
296 base::WrapUnique(new BluetoothGattServiceServiceProviderImpl( 296 base::MakeUnique<BluetoothGattServiceServiceProviderImpl>(
297 nullptr, dbus::ObjectPath(full_service_path), kFakeServiceUuid, 297 nullptr, dbus::ObjectPath(full_service_path), kFakeServiceUuid,
298 true, std::vector<dbus::ObjectPath>()))); 298 true, std::vector<dbus::ObjectPath>()));
299 return full_service_path; 299 return full_service_path;
300 } 300 }
301 301
302 std::string CreateFakeCharacteristic( 302 std::string CreateFakeCharacteristic(
303 BluetoothGattApplicationServiceProviderImpl* app_provider, 303 BluetoothGattApplicationServiceProviderImpl* app_provider,
304 const std::string& characteristic_path, 304 const std::string& characteristic_path,
305 const std::string& service_path) { 305 const std::string& service_path) {
306 const std::string& full_characteristic_path = 306 const std::string& full_characteristic_path =
307 service_path + "/" + characteristic_path; 307 service_path + "/" + characteristic_path;
308 app_provider->characteristic_providers_.push_back( 308 app_provider->characteristic_providers_.push_back(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 343
344 CreateFakeDescriptor(app_provider, "descriptor0", kCharacteristicPath1); 344 CreateFakeDescriptor(app_provider, "descriptor0", kCharacteristicPath1);
345 CreateFakeDescriptor(app_provider, "descriptor1", kCharacteristicPath2); 345 CreateFakeDescriptor(app_provider, "descriptor1", kCharacteristicPath2);
346 CreateFakeDescriptor(app_provider, "descriptor2", kCharacteristicPath3); 346 CreateFakeDescriptor(app_provider, "descriptor2", kCharacteristicPath3);
347 CreateFakeDescriptor(app_provider, "descriptor3", kCharacteristicPath1); 347 CreateFakeDescriptor(app_provider, "descriptor3", kCharacteristicPath1);
348 } 348 }
349 }; 349 };
350 350
351 TEST_F(BluetoothGattApplicationServiceProviderTest, GetManagedObjects) { 351 TEST_F(BluetoothGattApplicationServiceProviderTest, GetManagedObjects) {
352 std::unique_ptr<BluetoothGattApplicationServiceProviderImpl> app_provider = 352 std::unique_ptr<BluetoothGattApplicationServiceProviderImpl> app_provider =
353 base::WrapUnique(new BluetoothGattApplicationServiceProviderImpl( 353 base::MakeUnique<BluetoothGattApplicationServiceProviderImpl>(
354 nullptr, dbus::ObjectPath(kAppObjectPath), 354 nullptr, dbus::ObjectPath(kAppObjectPath),
355 std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>())); 355 std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>());
356 CreateFakeAttributes(app_provider.get()); 356 CreateFakeAttributes(app_provider.get());
357 357
358 dbus::MethodCall method_call("com.example.Interface", "SomeMethod"); 358 dbus::MethodCall method_call("com.example.Interface", "SomeMethod");
359 // Not setting the serial causes a crash. 359 // Not setting the serial causes a crash.
360 method_call.SetSerial(123); 360 method_call.SetSerial(123);
361 app_provider->GetManagedObjects( 361 app_provider->GetManagedObjects(
362 &method_call, base::Bind(&ResponseSenderCallback, kExpectedMessage)); 362 &method_call, base::Bind(&ResponseSenderCallback, kExpectedMessage));
363 } 363 }
364 364
365 TEST_F(BluetoothGattApplicationServiceProviderTest, SendValueChanged) { 365 TEST_F(BluetoothGattApplicationServiceProviderTest, SendValueChanged) {
366 std::unique_ptr<BluetoothGattApplicationServiceProviderImpl> app_provider = 366 std::unique_ptr<BluetoothGattApplicationServiceProviderImpl> app_provider =
367 base::WrapUnique(new BluetoothGattApplicationServiceProviderImpl( 367 base::MakeUnique<BluetoothGattApplicationServiceProviderImpl>(
368 nullptr, dbus::ObjectPath(kAppObjectPath), 368 nullptr, dbus::ObjectPath(kAppObjectPath),
369 std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>())); 369 std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>());
370 const std::string& kServicePath = 370 const std::string& kServicePath =
371 CreateFakeService(app_provider.get(), "service0"); 371 CreateFakeService(app_provider.get(), "service0");
372 const std::string& kCharacteristicPath = CreateFakeCharacteristic( 372 const std::string& kCharacteristicPath = CreateFakeCharacteristic(
373 app_provider.get(), "characteristic0", kServicePath); 373 app_provider.get(), "characteristic0", kServicePath);
374 374
375 std::vector<uint8_t> kNewValue = {0x13, 0x37, 0xba, 0xad, 0xf0}; 375 std::vector<uint8_t> kNewValue = {0x13, 0x37, 0xba, 0xad, 0xf0};
376 app_provider->SendValueChanged(dbus::ObjectPath(kCharacteristicPath), 376 app_provider->SendValueChanged(dbus::ObjectPath(kCharacteristicPath),
377 kNewValue); 377 kNewValue);
378 // TODO(rkc): Write a test implementation of dbus::Bus and 378 // TODO(rkc): Write a test implementation of dbus::Bus and
379 // dbus::ExportedObject so we can capture the actual signal that is sent and 379 // dbus::ExportedObject so we can capture the actual signal that is sent and
380 // verify its contents. 380 // verify its contents.
381 } 381 }
382 382
383 } // namespace bluez 383 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698