OLD | NEW |
(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 "base/memory/weak_ptr.h" |
| 6 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
| 7 #include "device/bluetooth/bluetooth_local_gatt_descriptor.h" |
| 8 #include "device/bluetooth/test/bluetooth_gatt_server_test.h" |
| 9 #include "device/bluetooth/test/bluetooth_test.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace device { |
| 13 |
| 14 class BluetoothLocalGattDescriptorTest : public BluetoothGattServerTest { |
| 15 public: |
| 16 void SetUp() override { |
| 17 BluetoothGattServerTest::SetUp(); |
| 18 |
| 19 StartGattSetup(); |
| 20 characteristic_ = BluetoothLocalGattCharacteristic::Create( |
| 21 BluetoothUUID(kTestUUIDGenericAttribute), |
| 22 device::BluetoothLocalGattCharacteristic::Properties(), |
| 23 device::BluetoothLocalGattCharacteristic::Permissions(), |
| 24 service_.get()); |
| 25 descriptor_ = BluetoothLocalGattDescriptor::Create( |
| 26 BluetoothUUID(kTestUUIDGenericAttribute), |
| 27 device::BluetoothLocalGattCharacteristic::Permissions(), |
| 28 characteristic_.get()); |
| 29 EXPECT_LT(0u, descriptor_->GetIdentifier().size()); |
| 30 CompleteGattSetup(); |
| 31 } |
| 32 |
| 33 protected: |
| 34 base::WeakPtr<BluetoothLocalGattCharacteristic> characteristic_; |
| 35 base::WeakPtr<BluetoothLocalGattDescriptor> descriptor_; |
| 36 }; |
| 37 |
| 38 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 39 TEST_F(BluetoothLocalGattDescriptorTest, ReadLocalDescriptorValue) { |
| 40 TestLocalGattServiceDelegate::value_to_write_ = 0x1337; |
| 41 SimulateLocalGattDescriptorValueReadRequest( |
| 42 service_.get(), descriptor_.get(), GetReadValueCallback(Call::EXPECTED), |
| 43 GetCallback(Call::NOT_EXPECTED)); |
| 44 |
| 45 EXPECT_EQ(TestLocalGattServiceDelegate::value_to_write_, |
| 46 GetInteger(last_read_value_)); |
| 47 } |
| 48 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 49 |
| 50 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 51 TEST_F(BluetoothLocalGattDescriptorTest, WriteLocalDescriptorValue) { |
| 52 const uint64_t kValueToWrite = 0x7331ul; |
| 53 SimulateLocalGattDescriptorValueWriteRequest( |
| 54 service_.get(), descriptor_.get(), GetValue(kValueToWrite), |
| 55 GetCallback(Call::EXPECTED), GetCallback(Call::NOT_EXPECTED)); |
| 56 |
| 57 EXPECT_EQ(kValueToWrite, TestLocalGattServiceDelegate::last_written_value_); |
| 58 } |
| 59 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 60 |
| 61 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 62 TEST_F(BluetoothLocalGattDescriptorTest, ReadLocalDescriptorValueFail) { |
| 63 TestLocalGattServiceDelegate::value_to_write_ = 0x1337; |
| 64 TestLocalGattServiceDelegate::should_fail_ = true; |
| 65 SimulateLocalGattDescriptorValueReadRequest( |
| 66 service_.get(), descriptor_.get(), |
| 67 GetReadValueCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED)); |
| 68 |
| 69 EXPECT_NE(TestLocalGattServiceDelegate::value_to_write_, |
| 70 GetInteger(last_read_value_)); |
| 71 } |
| 72 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 73 |
| 74 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 75 TEST_F(BluetoothLocalGattDescriptorTest, WriteLocalDescriptorValueFail) { |
| 76 const uint64_t kValueToWrite = 0x7331ul; |
| 77 TestLocalGattServiceDelegate::should_fail_ = true; |
| 78 SimulateLocalGattDescriptorValueWriteRequest( |
| 79 service_.get(), descriptor_.get(), GetValue(kValueToWrite), |
| 80 GetCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED)); |
| 81 |
| 82 EXPECT_NE(kValueToWrite, TestLocalGattServiceDelegate::last_written_value_); |
| 83 } |
| 84 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 85 |
| 86 } // namespace device |
OLD | NEW |