summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/test/mock_bluetooth_gatt_service.cc
blob: 148208aeee4dc7cd1ee9c096d9d8d8d24d2e4b4b (plain)
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
// Copyright 2014 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_gatt_service.h"

#include <utility>

#include "device/bluetooth/test/mock_bluetooth_device.h"

using testing::Return;
using testing::_;

namespace device {

MockBluetoothGattService::MockBluetoothGattService(
    MockBluetoothDevice* device,
    const std::string& identifier,
    const BluetoothUUID& uuid,
    bool is_primary,
    bool is_local) {
  ON_CALL(*this, GetIdentifier()).WillByDefault(Return(identifier));
  ON_CALL(*this, GetUUID()).WillByDefault(Return(uuid));
  ON_CALL(*this, IsLocal()).WillByDefault(Return(is_local));
  ON_CALL(*this, IsPrimary()).WillByDefault(Return(is_primary));
  ON_CALL(*this, GetDevice()).WillByDefault(Return(device));
  ON_CALL(*this, GetCharacteristics())
      .WillByDefault(Return(std::vector<BluetoothGattCharacteristic*>()));
  ON_CALL(*this, GetIncludedServices())
      .WillByDefault(Return(std::vector<BluetoothGattService*>()));
  ON_CALL(*this, GetCharacteristic(_))
      .WillByDefault(Return(static_cast<BluetoothGattCharacteristic*>(NULL)));
}

MockBluetoothGattService::~MockBluetoothGattService() {
}

void MockBluetoothGattService::AddMockCharacteristic(
    scoped_ptr<MockBluetoothGattCharacteristic> mock_characteristic) {
  mock_characteristics_.push_back(std::move(mock_characteristic));
}

std::vector<BluetoothGattCharacteristic*>
MockBluetoothGattService::GetMockCharacteristics() const {
  std::vector<BluetoothGattCharacteristic*> characteristics;
  for (BluetoothGattCharacteristic* characteristic : mock_characteristics_) {
    characteristics.push_back(characteristic);
  }
  return characteristics;
}

BluetoothGattCharacteristic* MockBluetoothGattService::GetMockCharacteristic(
    const std::string& identifier) const {
  for (BluetoothGattCharacteristic* characteristic : mock_characteristics_) {
    if (characteristic->GetIdentifier() == identifier) {
      return characteristic;
    }
  }
  return nullptr;
}

}  // namespace device