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

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

Issue 2783733002: Bluetooth: Add service data unit tests for chromeos (Closed)
Patch Set: Created 3 years, 8 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "device/bluetooth/dbus/fake_bluetooth_device_client.h" 5 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <sys/socket.h> 9 #include <sys/socket.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
(...skipping 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 void FakeBluetoothDeviceClient::RemoveAllDevices() { 1768 void FakeBluetoothDeviceClient::RemoveAllDevices() {
1769 device_list_.clear(); 1769 device_list_.clear();
1770 } 1770 }
1771 1771
1772 void FakeBluetoothDeviceClient::CreateTestDevice( 1772 void FakeBluetoothDeviceClient::CreateTestDevice(
1773 const dbus::ObjectPath& adapter_path, 1773 const dbus::ObjectPath& adapter_path,
1774 const base::Optional<std::string> name, 1774 const base::Optional<std::string> name,
1775 const std::string alias, 1775 const std::string alias,
1776 const std::string device_address, 1776 const std::string device_address,
1777 const std::vector<std::string>& service_uuids, 1777 const std::vector<std::string>& service_uuids,
1778 device::BluetoothTransport type) { 1778 device::BluetoothTransport type,
1779 const std::unordered_map<std::string, std::vector<uint8_t>>& service_data) {
1779 // Create a random device path. 1780 // Create a random device path.
1780 dbus::ObjectPath device_path; 1781 dbus::ObjectPath device_path;
1781 std::string id; 1782 std::string id;
1782 do { 1783 do {
1783 // Construct an id that is valid according to the DBUS specification. 1784 // Construct an id that is valid according to the DBUS specification.
1784 base::Base64Encode(base::RandBytesAsString(10), &id); 1785 base::Base64Encode(base::RandBytesAsString(10), &id);
1785 base::RemoveChars(id, "+/=", &id); 1786 base::RemoveChars(id, "+/=", &id);
1786 device_path = dbus::ObjectPath(adapter_path.value() + "/dev" + id); 1787 device_path = dbus::ObjectPath(adapter_path.value() + "/dev" + id);
1787 } while (std::find(device_list_.begin(), device_list_.end(), device_path) != 1788 } while (std::find(device_list_.begin(), device_list_.end(), device_path) !=
1788 device_list_.end()); 1789 device_list_.end());
(...skipping 21 matching lines...) Expand all
1810 case device::BLUETOOTH_TRANSPORT_LE: 1811 case device::BLUETOOTH_TRANSPORT_LE:
1811 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeLe); 1812 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeLe);
1812 break; 1813 break;
1813 case device::BLUETOOTH_TRANSPORT_DUAL: 1814 case device::BLUETOOTH_TRANSPORT_DUAL:
1814 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeDual); 1815 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeDual);
1815 break; 1816 break;
1816 default: 1817 default:
1817 NOTREACHED(); 1818 NOTREACHED();
1818 } 1819 }
1819 properties->type.set_valid(true); 1820 properties->type.set_valid(true);
1821 properties->service_data.ReplaceValue(service_data);
1822 properties->service_data.set_valid(true);
Miao 2017/03/28 22:56:40 The validity of |service_data| should depend on wh
xiaoyinh(OOO Sep 11-29) 2017/03/29 21:58:06 Done.
1820 1823
1821 properties_map_.insert(std::make_pair(device_path, std::move(properties))); 1824 properties_map_.insert(std::make_pair(device_path, std::move(properties)));
1822 device_list_.push_back(device_path); 1825 device_list_.push_back(device_path);
1823 for (auto& observer : observers_) 1826 for (auto& observer : observers_)
1824 observer.DeviceAdded(device_path); 1827 observer.DeviceAdded(device_path);
1825 } 1828 }
1826 1829
1827 } // namespace bluez 1830 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698