Chromium Code Reviews| Index: device/bluetooth/bluetooth_local_gatt_characteristic_unittest.cc |
| diff --git a/device/bluetooth/bluetooth_local_gatt_characteristic_unittest.cc b/device/bluetooth/bluetooth_local_gatt_characteristic_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e74e7e9d60441ba3a06adc2befc52d3b8c516a02 |
| --- /dev/null |
| +++ b/device/bluetooth/bluetooth_local_gatt_characteristic_unittest.cc |
| @@ -0,0 +1,81 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/memory/weak_ptr.h" |
| +#include "device/bluetooth/bluetooth_local_gatt_characteristic.h" |
| +#include "device/bluetooth/test/bluetooth_gatt_server_test.h" |
| +#include "device/bluetooth/test/bluetooth_test.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace device { |
| + |
| +class BluetoothLocalGattCharacteristicTest : public BluetoothGattServerTest { |
| + public: |
| + void SetUp() override { |
| + BluetoothGattServerTest::SetUp(); |
| + |
| + StartGattSetup(); |
| + characteristic_ = BluetoothLocalGattCharacteristic::Create( |
| + BluetoothUUID(kTestUUIDGenericAttribute), |
| + device::BluetoothLocalGattCharacteristic::Properties(), |
| + device::BluetoothLocalGattCharacteristic::Permissions(), |
| + service_.get()); |
| + EXPECT_LT(0u, characteristic_->GetIdentifier().size()); |
| + CompleteGattSetup(); |
| + } |
| + |
| + protected: |
| + base::WeakPtr<BluetoothLocalGattCharacteristic> characteristic_; |
| +}; |
| + |
| +#if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| +TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValue) { |
| + TestLocalGattServiceDelegate::value_to_write_ = 0x1337; |
|
scheib
2016/05/03 05:55:57
Instead of statics for ::value_to_write etc, why n
rkc
2016/05/03 18:22:15
Done.
|
| + SimulateLocalGattCharacteristicValueReadRequest( |
| + service_.get(), characteristic_.get(), |
| + GetReadValueCallback(Call::EXPECTED), GetCallback(Call::NOT_EXPECTED)); |
| + |
| + EXPECT_EQ(TestLocalGattServiceDelegate::value_to_write_, |
| + GetInteger(last_read_value_)); |
| +} |
| +#endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
| + |
| +#if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| +TEST_F(BluetoothLocalGattCharacteristicTest, WriteLocalCharacteristicValue) { |
| + const uint64_t kValueToWrite = 0x7331ul; |
| + SimulateLocalGattCharacteristicValueWriteRequest( |
| + service_.get(), characteristic_.get(), GetValue(kValueToWrite), |
| + GetCallback(Call::EXPECTED), GetCallback(Call::NOT_EXPECTED)); |
| + |
| + EXPECT_EQ(kValueToWrite, TestLocalGattServiceDelegate::last_written_value_); |
| +} |
| +#endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
| + |
| +#if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| +TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValueFail) { |
| + TestLocalGattServiceDelegate::value_to_write_ = 0x1337; |
| + TestLocalGattServiceDelegate::should_fail_ = true; |
| + SimulateLocalGattCharacteristicValueReadRequest( |
| + service_.get(), characteristic_.get(), |
| + GetReadValueCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED)); |
| + |
| + EXPECT_NE(TestLocalGattServiceDelegate::value_to_write_, |
| + GetInteger(last_read_value_)); |
| +} |
| +#endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
| + |
| +#if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| +TEST_F(BluetoothLocalGattCharacteristicTest, |
| + WriteLocalCharacteristicValueFail) { |
| + const uint64_t kValueToWrite = 0x7331ul; |
| + TestLocalGattServiceDelegate::should_fail_ = true; |
| + SimulateLocalGattCharacteristicValueWriteRequest( |
| + service_.get(), characteristic_.get(), GetValue(kValueToWrite), |
| + GetCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED)); |
| + |
| + EXPECT_NE(kValueToWrite, TestLocalGattServiceDelegate::last_written_value_); |
| +} |
| +#endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
| + |
| +} // namespace device |