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

Side by Side Diff: device/bluetooth/test/bluetooth_gatt_server_test.cc

Issue 1919683002: Adapter changes for implementing local GATT attributes and tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dbus_classes
Patch Set: Created 4 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "device/bluetooth/test/bluetooth_gatt_server_test.h"
6
7 #include "base/logging.h"
8 #include "base/memory/ptr_util.h"
9 #include "base/memory/ref_counted.h"
10 #include "device/bluetooth/bluetooth_uuid.h"
11 #include "device/bluetooth/test/bluetooth_test.h"
12
13 namespace device {
14
15 BluetoothGattServerTest::BluetoothGattServerTest() {}
16
17 BluetoothGattServerTest::~BluetoothGattServerTest() {}
18
19 void BluetoothGattServerTest::StartGattSetup() {
20 InitWithFakeAdapter();
21 delegate_ = base::WrapUnique(new TestBluetoothLocalGattServiceDelegate());
22 service_ = BluetoothLocalGattService::Create(
23 adapter_.get(), BluetoothUUID(kTestUUIDGenericAttribute), true, nullptr,
24 delegate_.get());
25 delegate_->set_expected_service(service_.get());
26 }
27
28 void BluetoothGattServerTest::CompleteGattSetup() {
29 service_->Register(GetCallback(Call::EXPECTED),
30 GetGattErrorCallback(Call::NOT_EXPECTED));
31 EXPECT_EQ(1, callback_count_);
32 EXPECT_EQ(0, error_callback_count_);
33 }
34
35 void BluetoothGattServerTest::SetUp() {
36 BluetoothTest::SetUp();
37
38 last_read_value_ = std::vector<uint8_t>();
39 }
40
41 void BluetoothGattServerTest::TearDown() {
42 int callback_count = callback_count_;
43 int error_callback_count = error_callback_count_;
44 service_->Unregister(GetCallback(Call::EXPECTED),
45 GetGattErrorCallback(Call::NOT_EXPECTED));
46 EXPECT_EQ(callback_count + 1, callback_count_);
47 EXPECT_EQ(error_callback_count, error_callback_count_);
48
49 delegate_ = nullptr;
50
51 BluetoothTest::TearDown();
52 }
53
54 // static
55 uint64_t BluetoothGattServerTest::GetInteger(
56 const std::vector<uint8_t>& value) {
57 // Handling only up to 4 bytes value for tests.
58 CHECK_LE(value.size(), 4u);
59 uint64_t int_value = 0;
60 uint64_t powers_of_256 = 1;
61 for (uint8_t v : value) {
62 int_value += v * powers_of_256;
63 powers_of_256 *= 256;
64 }
65 return int_value;
66 }
67
68 // static
69 std::vector<uint8_t> BluetoothGattServerTest::GetValue(uint64_t int_value) {
70 CHECK_LE(int_value, 0xFFFFFFFFul);
71 std::vector<uint8_t> value;
72 while (int_value) {
73 value.push_back(int_value & 0xff);
74 int_value >>= 8;
75 }
76 return value;
77 }
78
79 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/test/bluetooth_gatt_server_test.h ('k') | device/bluetooth/test/bluetooth_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698