| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 std::vector<uint8_t> empty_vector; | 489 std::vector<uint8_t> empty_vector; |
| 490 SimulateGattCharacteristicRead(characteristic1_, empty_vector); | 490 SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| 491 | 491 |
| 492 EXPECT_EQ(1, gatt_read_characteristic_attempts_); | 492 EXPECT_EQ(1, gatt_read_characteristic_attempts_); |
| 493 EXPECT_EQ(test_vector, last_read_value_); | 493 EXPECT_EQ(test_vector, last_read_value_); |
| 494 EXPECT_EQ(test_vector, characteristic1_->GetValue()); | 494 EXPECT_EQ(test_vector, characteristic1_->GetValue()); |
| 495 } | 495 } |
| 496 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 496 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 497 | 497 |
| 498 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 498 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 499 // Callback that make sure GattCharacteristicValueChanged has been called | |
| 500 // before the callback runs. | |
| 501 static void test_callback( | |
| 502 BluetoothRemoteGattCharacteristic::ValueCallback callback, | |
| 503 const TestBluetoothAdapterObserver& callback_observer, | |
| 504 const std::vector<uint8_t>& value) { | |
| 505 EXPECT_EQ(1, callback_observer.gatt_characteristic_value_changed_count()); | |
| 506 callback.Run(value); | |
| 507 } | |
| 508 | |
| 509 // Tests that ReadRemoteCharacteristic results in a | |
| 510 // GattCharacteristicValueChanged call. | |
| 511 TEST_F(BluetoothRemoteGattCharacteristicTest, | |
| 512 ReadRemoteCharacteristic_GattCharacteristicValueChanged) { | |
| 513 if (!PlatformSupportsLowEnergy()) { | |
| 514 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
| 515 return; | |
| 516 } | |
| 517 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( | |
| 518 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); | |
| 519 | |
| 520 TestBluetoothAdapterObserver observer(adapter_); | |
| 521 | |
| 522 characteristic1_->ReadRemoteCharacteristic( | |
| 523 base::Bind(test_callback, GetReadValueCallback(Call::EXPECTED), | |
| 524 base::ConstRef(observer)), | |
| 525 GetGattErrorCallback(Call::NOT_EXPECTED)); | |
| 526 | |
| 527 std::vector<uint8_t> test_vector = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; | |
| 528 SimulateGattCharacteristicRead(characteristic1_, test_vector); | |
| 529 | |
| 530 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | |
| 531 EXPECT_EQ(characteristic1_->GetIdentifier(), | |
| 532 observer.last_gatt_characteristic_id()); | |
| 533 EXPECT_EQ(characteristic1_->GetUUID(), | |
| 534 observer.last_gatt_characteristic_uuid()); | |
| 535 EXPECT_EQ(test_vector, observer.last_changed_characteristic_value()); | |
| 536 } | |
| 537 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | |
| 538 | |
| 539 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | |
| 540 // Tests WriteRemoteCharacteristic with non-empty value buffer. | 499 // Tests WriteRemoteCharacteristic with non-empty value buffer. |
| 541 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic) { | 500 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic) { |
| 542 if (!PlatformSupportsLowEnergy()) { | 501 if (!PlatformSupportsLowEnergy()) { |
| 543 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 502 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 544 return; | 503 return; |
| 545 } | 504 } |
| 546 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( | 505 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 547 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); | 506 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); |
| 548 | 507 |
| 549 TestBluetoothAdapterObserver observer(adapter_); | 508 TestBluetoothAdapterObserver observer(adapter_); |
| (...skipping 1634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2184 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); | 2143 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); |
| 2185 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); | 2144 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); |
| 2186 | 2145 |
| 2187 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); | 2146 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); |
| 2188 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); | 2147 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); |
| 2189 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); | 2148 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); |
| 2190 } | 2149 } |
| 2191 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 2150 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 2192 | 2151 |
| 2193 } // namespace device | 2152 } // namespace device |
| OLD | NEW |