| 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..dc70e73da90138fb868399321cd22df498e0d762
|
| --- /dev/null
|
| +++ b/device/bluetooth/bluetooth_local_gatt_characteristic_unittest.cc
|
| @@ -0,0 +1,80 @@
|
| +// 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());
|
| + CompleteGattSetup();
|
| + }
|
| +
|
| + protected:
|
| + base::WeakPtr<BluetoothLocalGattCharacteristic> characteristic_;
|
| +};
|
| +
|
| +#if defined(OS_CHROMEOS) || defined(OS_LINUX)
|
| +TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValue) {
|
| + TestLocalGattServiceDelegate::value_to_write_ = 0x1337;
|
| + 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
|
|
|