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