1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "device/bluetooth/test/mock_bluetooth_device.h"
#include <utility>
#include "base/strings/utf_string_conversions.h"
#include "device/bluetooth/bluetooth_gatt_service.h"
#include "device/bluetooth/test/mock_bluetooth_adapter.h"
namespace device {
MockBluetoothDevice::MockBluetoothDevice(MockBluetoothAdapter* adapter,
uint32_t bluetooth_class,
const std::string& name,
const std::string& address,
bool paired,
bool connected)
: BluetoothDevice(adapter),
bluetooth_class_(bluetooth_class),
name_(name),
address_(address) {
ON_CALL(*this, GetBluetoothClass())
.WillByDefault(testing::Return(bluetooth_class_));
ON_CALL(*this, GetDeviceName())
.WillByDefault(testing::Return(name_));
ON_CALL(*this, GetIdentifier())
.WillByDefault(testing::Return(address_ + "-Identifier"));
ON_CALL(*this, GetAddress())
.WillByDefault(testing::Return(address_));
ON_CALL(*this, GetDeviceType())
.WillByDefault(testing::Return(DEVICE_UNKNOWN));
ON_CALL(*this, GetVendorIDSource())
.WillByDefault(testing::Return(VENDOR_ID_UNKNOWN));
ON_CALL(*this, GetVendorID())
.WillByDefault(testing::Return(0));
ON_CALL(*this, GetProductID())
.WillByDefault(testing::Return(0));
ON_CALL(*this, GetDeviceID())
.WillByDefault(testing::Return(0));
ON_CALL(*this, IsPaired())
.WillByDefault(testing::Return(paired));
ON_CALL(*this, IsConnected())
.WillByDefault(testing::Return(connected));
ON_CALL(*this, IsConnectable())
.WillByDefault(testing::Return(false));
ON_CALL(*this, IsConnecting())
.WillByDefault(testing::Return(false));
ON_CALL(*this, GetName())
.WillByDefault(testing::Return(base::UTF8ToUTF16(name_)));
ON_CALL(*this, ExpectingPinCode())
.WillByDefault(testing::Return(false));
ON_CALL(*this, ExpectingPasskey())
.WillByDefault(testing::Return(false));
ON_CALL(*this, ExpectingConfirmation())
.WillByDefault(testing::Return(false));
ON_CALL(*this, GetUUIDs())
.WillByDefault(testing::Return(uuids_));
}
MockBluetoothDevice::~MockBluetoothDevice() {}
void MockBluetoothDevice::AddMockService(
scoped_ptr<MockBluetoothGattService> mock_service) {
mock_services_.push_back(std::move(mock_service));
}
std::vector<BluetoothGattService*> MockBluetoothDevice::GetMockServices()
const {
std::vector<BluetoothGattService*> services;
for (BluetoothGattService* service : mock_services_) {
services.push_back(service);
}
return services;
}
BluetoothGattService* MockBluetoothDevice::GetMockService(
const std::string& identifier) const {
for (BluetoothGattService* service : mock_services_) {
if (service->GetIdentifier() == identifier)
return service;
}
return nullptr;
}
} // namespace device
|