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

Side by Side Diff: device/bluetooth/bluetooth_gatt_bluez_unittest.cc

Issue 1542163002: Switch to standard integer types in device/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: win Created 4 years, 12 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h>
6 #include <stdint.h>
7
5 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
6 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 10 #include "base/run_loop.h"
8 #include "dbus/object_path.h" 11 #include "dbus/object_path.h"
9 #include "device/bluetooth/bluetooth_adapter.h" 12 #include "device/bluetooth/bluetooth_adapter.h"
10 #include "device/bluetooth/bluetooth_adapter_factory.h" 13 #include "device/bluetooth/bluetooth_adapter_factory.h"
11 #include "device/bluetooth/bluetooth_device.h" 14 #include "device/bluetooth/bluetooth_device.h"
12 #include "device/bluetooth/bluetooth_gatt_characteristic.h" 15 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
13 #include "device/bluetooth/bluetooth_gatt_connection.h" 16 #include "device/bluetooth/bluetooth_gatt_connection.h"
14 #include "device/bluetooth/bluetooth_gatt_descriptor.h" 17 #include "device/bluetooth/bluetooth_gatt_descriptor.h"
(...skipping 27 matching lines...) Expand all
42 45
43 const BluetoothUUID kHeartRateMeasurementUUID( 46 const BluetoothUUID kHeartRateMeasurementUUID(
44 bluez::FakeBluetoothGattCharacteristicClient::kHeartRateMeasurementUUID); 47 bluez::FakeBluetoothGattCharacteristicClient::kHeartRateMeasurementUUID);
45 const BluetoothUUID kBodySensorLocationUUID( 48 const BluetoothUUID kBodySensorLocationUUID(
46 bluez::FakeBluetoothGattCharacteristicClient::kBodySensorLocationUUID); 49 bluez::FakeBluetoothGattCharacteristicClient::kBodySensorLocationUUID);
47 const BluetoothUUID kHeartRateControlPointUUID( 50 const BluetoothUUID kHeartRateControlPointUUID(
48 bluez::FakeBluetoothGattCharacteristicClient::kHeartRateControlPointUUID); 51 bluez::FakeBluetoothGattCharacteristicClient::kHeartRateControlPointUUID);
49 52
50 // Compares GATT characteristic/descriptor values. Returns true, if the values 53 // Compares GATT characteristic/descriptor values. Returns true, if the values
51 // are equal. 54 // are equal.
52 bool ValuesEqual(const std::vector<uint8>& value0, 55 bool ValuesEqual(const std::vector<uint8_t>& value0,
53 const std::vector<uint8>& value1) { 56 const std::vector<uint8_t>& value1) {
54 if (value0.size() != value1.size()) 57 if (value0.size() != value1.size())
55 return false; 58 return false;
56 for (size_t i = 0; i < value0.size(); ++i) 59 for (size_t i = 0; i < value0.size(); ++i)
57 if (value0[i] != value1[i]) 60 if (value0[i] != value1[i])
58 return false; 61 return false;
59 return true; 62 return true;
60 } 63 }
61 64
62 } // namespace 65 } // namespace
63 66
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 ASSERT_TRUE(adapter_->IsInitialized()); 124 ASSERT_TRUE(adapter_->IsInitialized());
122 ASSERT_TRUE(adapter_->IsPresent()); 125 ASSERT_TRUE(adapter_->IsPresent());
123 } 126 }
124 127
125 void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) { 128 void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) {
126 adapter_ = adapter; 129 adapter_ = adapter;
127 } 130 }
128 131
129 void SuccessCallback() { ++success_callback_count_; } 132 void SuccessCallback() { ++success_callback_count_; }
130 133
131 void ValueCallback(const std::vector<uint8>& value) { 134 void ValueCallback(const std::vector<uint8_t>& value) {
132 ++success_callback_count_; 135 ++success_callback_count_;
133 last_read_value_ = value; 136 last_read_value_ = value;
134 } 137 }
135 138
136 void GattConnectionCallback(scoped_ptr<BluetoothGattConnection> conn) { 139 void GattConnectionCallback(scoped_ptr<BluetoothGattConnection> conn) {
137 ++success_callback_count_; 140 ++success_callback_count_;
138 gatt_conn_ = conn.Pass(); 141 gatt_conn_ = conn.Pass();
139 } 142 }
140 143
141 void NotifySessionCallback(scoped_ptr<BluetoothGattNotifySession> session) { 144 void NotifySessionCallback(scoped_ptr<BluetoothGattNotifySession> session) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 bluez::FakeBluetoothGattCharacteristicClient* 177 bluez::FakeBluetoothGattCharacteristicClient*
175 fake_bluetooth_gatt_characteristic_client_; 178 fake_bluetooth_gatt_characteristic_client_;
176 bluez::FakeBluetoothGattDescriptorClient* 179 bluez::FakeBluetoothGattDescriptorClient*
177 fake_bluetooth_gatt_descriptor_client_; 180 fake_bluetooth_gatt_descriptor_client_;
178 scoped_ptr<device::BluetoothGattConnection> gatt_conn_; 181 scoped_ptr<device::BluetoothGattConnection> gatt_conn_;
179 ScopedVector<BluetoothGattNotifySession> update_sessions_; 182 ScopedVector<BluetoothGattNotifySession> update_sessions_;
180 scoped_refptr<BluetoothAdapter> adapter_; 183 scoped_refptr<BluetoothAdapter> adapter_;
181 184
182 int success_callback_count_; 185 int success_callback_count_;
183 int error_callback_count_; 186 int error_callback_count_;
184 std::vector<uint8> last_read_value_; 187 std::vector<uint8_t> last_read_value_;
185 BluetoothGattService::GattErrorCode last_service_error_; 188 BluetoothGattService::GattErrorCode last_service_error_;
186 }; 189 };
187 190
188 TEST_F(BluetoothGattBlueZTest, GattConnection) { 191 TEST_F(BluetoothGattBlueZTest, GattConnection) {
189 fake_bluetooth_device_client_->CreateDevice( 192 fake_bluetooth_device_client_->CreateDevice(
190 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 193 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
191 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 194 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
192 BluetoothDevice* device = 195 BluetoothDevice* device =
193 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 196 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
194 ASSERT_TRUE(device); 197 ASSERT_TRUE(device);
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 device->GetGattService(observer.last_gatt_service_id()); 633 device->GetGattService(observer.last_gatt_service_id());
631 634
632 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); 635 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
633 636
634 // Run the message loop so that the characteristics appear. 637 // Run the message loop so that the characteristics appear.
635 base::MessageLoop::current()->Run(); 638 base::MessageLoop::current()->Run();
636 639
637 // Issue write request to non-writable characteristics. 640 // Issue write request to non-writable characteristics.
638 observer.Reset(); 641 observer.Reset();
639 642
640 std::vector<uint8> write_value; 643 std::vector<uint8_t> write_value;
641 write_value.push_back(0x01); 644 write_value.push_back(0x01);
642 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( 645 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic(
643 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath() 646 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath()
644 .value()); 647 .value());
645 ASSERT_TRUE(characteristic); 648 ASSERT_TRUE(characteristic);
646 EXPECT_FALSE(characteristic->IsNotifying()); 649 EXPECT_FALSE(characteristic->IsNotifying());
647 EXPECT_EQ( 650 EXPECT_EQ(
648 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath() 651 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath()
649 .value(), 652 .value(),
650 characteristic->GetIdentifier()); 653 characteristic->GetIdentifier());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 base::Unretained(this))); 707 base::Unretained(this)));
705 EXPECT_TRUE(observer.last_gatt_characteristic_id().empty()); 708 EXPECT_TRUE(observer.last_gatt_characteristic_id().empty());
706 EXPECT_FALSE(observer.last_gatt_characteristic_uuid().IsValid()); 709 EXPECT_FALSE(observer.last_gatt_characteristic_uuid().IsValid());
707 EXPECT_EQ(1, success_callback_count_); 710 EXPECT_EQ(1, success_callback_count_);
708 EXPECT_EQ(2, error_callback_count_); 711 EXPECT_EQ(2, error_callback_count_);
709 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); 712 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
710 713
711 // Issue some invalid write requests to the characteristic. 714 // Issue some invalid write requests to the characteristic.
712 // The value should still not change. 715 // The value should still not change.
713 716
714 std::vector<uint8> invalid_write_length; 717 std::vector<uint8_t> invalid_write_length;
715 invalid_write_length.push_back(0x01); 718 invalid_write_length.push_back(0x01);
716 invalid_write_length.push_back(0x00); 719 invalid_write_length.push_back(0x00);
717 characteristic->WriteRemoteCharacteristic( 720 characteristic->WriteRemoteCharacteristic(
718 invalid_write_length, base::Bind(&BluetoothGattBlueZTest::SuccessCallback, 721 invalid_write_length, base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
719 base::Unretained(this)), 722 base::Unretained(this)),
720 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, 723 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
721 base::Unretained(this))); 724 base::Unretained(this)));
722 EXPECT_EQ(1, success_callback_count_); 725 EXPECT_EQ(1, success_callback_count_);
723 EXPECT_EQ(3, error_callback_count_); 726 EXPECT_EQ(3, error_callback_count_);
724 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, 727 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH,
725 last_service_error_); 728 last_service_error_);
726 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); 729 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
727 730
728 std::vector<uint8> invalid_write_value; 731 std::vector<uint8_t> invalid_write_value;
729 invalid_write_value.push_back(0x02); 732 invalid_write_value.push_back(0x02);
730 characteristic->WriteRemoteCharacteristic( 733 characteristic->WriteRemoteCharacteristic(
731 invalid_write_value, base::Bind(&BluetoothGattBlueZTest::SuccessCallback, 734 invalid_write_value, base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
732 base::Unretained(this)), 735 base::Unretained(this)),
733 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, 736 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
734 base::Unretained(this))); 737 base::Unretained(this)));
735 EXPECT_EQ(1, success_callback_count_); 738 EXPECT_EQ(1, success_callback_count_);
736 EXPECT_EQ(4, error_callback_count_); 739 EXPECT_EQ(4, error_callback_count_);
737 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_service_error_); 740 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_service_error_);
738 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); 741 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 1251
1249 EXPECT_EQ(1, success_callback_count_); 1252 EXPECT_EQ(1, success_callback_count_);
1250 EXPECT_EQ(0, error_callback_count_); 1253 EXPECT_EQ(0, error_callback_count_);
1251 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1254 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1252 EXPECT_TRUE(characteristic->IsNotifying()); 1255 EXPECT_TRUE(characteristic->IsNotifying());
1253 EXPECT_EQ(1U, update_sessions_.size()); 1256 EXPECT_EQ(1U, update_sessions_.size());
1254 EXPECT_TRUE(update_sessions_[0]->IsActive()); 1257 EXPECT_TRUE(update_sessions_[0]->IsActive());
1255 } 1258 }
1256 1259
1257 } // namespace bluez 1260 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_discovery_session.h ('k') | device/bluetooth/bluetooth_gatt_characteristic.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698