| Index: device/bluetooth/bluez/bluetooth_service_attribute_value_bluez_unittest.cc
|
| diff --git a/device/bluetooth/bluez/bluetooth_service_attribute_value_bluez_unittest.cc b/device/bluetooth/bluez/bluetooth_service_attribute_value_bluez_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f6e7c1f40fd246a2cadeee83ac6452887bc6f0d9
|
| --- /dev/null
|
| +++ b/device/bluetooth/bluez/bluetooth_service_attribute_value_bluez_unittest.cc
|
| @@ -0,0 +1,117 @@
|
| +// 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 "device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.h"
|
| +
|
| +#include <cstdint>
|
| +
|
| +#include "base/values.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace bluez {
|
| +
|
| +namespace {
|
| +
|
| +using Type = BluetoothServiceAttributeValueBlueZ::Type;
|
| +using ValueType = BluetoothServiceAttributeValueBlueZ::ValueType;
|
| +using Sequence = BluetoothServiceAttributeValueBlueZ::Sequence;
|
| +
|
| +// constexpr uint16_t kServiceUuidAttributeId = 0x0003;
|
| +constexpr char kServiceUuid[] = "00001801-0000-1000-8000-00805f9b34fb";
|
| +
|
| +void CheckUuidValue(const BluetoothServiceAttributeValueBlueZ& value,
|
| + const std::string& uuid) {
|
| + EXPECT_EQ(Type::UUID, value.get_type());
|
| + std::string str;
|
| + EXPECT_TRUE(value.get_value().value->GetAsString(&str));
|
| + EXPECT_EQ(uuid, str);
|
| +}
|
| +
|
| +void CheckIntValue(const BluetoothServiceAttributeValueBlueZ& value,
|
| + uint32_t val) {
|
| + EXPECT_EQ(Type::INT, value.get_type());
|
| + int i_val;
|
| + EXPECT_TRUE(value.get_value().value->GetAsInteger(&i_val));
|
| + EXPECT_EQ(val, static_cast<uint32_t>(i_val));
|
| +}
|
| +}
|
| +
|
| +TEST(BluetoothServiceAttributeBlueZTest, BasicValue) {
|
| + BluetoothServiceAttributeValueBlueZ value1(
|
| + Type::UUID, 16, new base::StringValue(kServiceUuid));
|
| + BluetoothServiceAttributeValueBlueZ value2 = value1;
|
| +
|
| + CheckUuidValue(value2, kServiceUuid);
|
| +}
|
| +
|
| +TEST(BluetoothServiceAttributeBlueZTest, Sequence) {
|
| + BluetoothServiceAttributeValueBlueZ value1(
|
| + Type::UUID, 16, new base::StringValue(kServiceUuid));
|
| + BluetoothServiceAttributeValueBlueZ value2(
|
| + Type::INT, 4, new base::FundamentalValue(0x1337));
|
| + BluetoothServiceAttributeValueBlueZ value3(
|
| + Type::INT, 4, new base::FundamentalValue(0x7331));
|
| +
|
| + BluetoothServiceAttributeValueBlueZ* value4 =
|
| + new BluetoothServiceAttributeValueBlueZ(
|
| + Type::SEQUENCE, 3, new Sequence({value1, value2, value3}));
|
| + BluetoothServiceAttributeValueBlueZ value = *value4;
|
| + delete value4;
|
| +
|
| + EXPECT_EQ(3u, value.get_size());
|
| + Sequence* s = value.get_value().sequence;
|
| + EXPECT_EQ(3u, s->size());
|
| +
|
| + CheckUuidValue((*s)[0], kServiceUuid);
|
| + CheckIntValue((*s)[2], 0x7331); // Checking out of order by intention.
|
| + CheckIntValue((*s)[1], 0x1337);
|
| +}
|
| +
|
| +TEST(BluetoothServiceAttributeBlueZTest, NestedValue) {
|
| + BluetoothServiceAttributeValueBlueZ value1(
|
| + Type::UUID, 16, new base::StringValue(kServiceUuid));
|
| + BluetoothServiceAttributeValueBlueZ value2(
|
| + Type::INT, 4, new base::FundamentalValue(0x1337));
|
| + BluetoothServiceAttributeValueBlueZ value3(Type::SEQUENCE, 2,
|
| + new Sequence({value1, value2}));
|
| + BluetoothServiceAttributeValueBlueZ value4(Type::SEQUENCE, 1,
|
| + new Sequence({value3}));
|
| +
|
| + BluetoothServiceAttributeValueBlueZ* value5 =
|
| + new BluetoothServiceAttributeValueBlueZ(
|
| + Type::SEQUENCE, 4, new Sequence({value1, value2, value3, value4}));
|
| + BluetoothServiceAttributeValueBlueZ value = *value5;
|
| + delete value5;
|
| +
|
| + // Check outer layer first.
|
| + EXPECT_EQ(4u, value.get_size());
|
| + Sequence* v5 = value.get_value().sequence;
|
| + EXPECT_EQ(4u, v5->size());
|
| + CheckUuidValue((*v5)[0], kServiceUuid);
|
| + CheckIntValue((*v5)[1], 0x1337);
|
| +
|
| + // Check value3 again.
|
| + EXPECT_EQ(2u, (*v5)[2].get_size());
|
| + EXPECT_EQ(Type::SEQUENCE, (*v5)[2].get_type());
|
| + Sequence* v3 = (*v5)[2].get_value().sequence;
|
| + EXPECT_EQ(2u, v3->size());
|
| + CheckUuidValue((*v3)[0], kServiceUuid);
|
| + CheckIntValue((*v3)[1], 0x1337);
|
| +
|
| + // Check value4 now.
|
| + EXPECT_EQ(1u, (*v5)[3].get_size());
|
| + EXPECT_EQ(Type::SEQUENCE, (*v5)[3].get_type());
|
| + Sequence* v4 = (*v5)[3].get_value().sequence;
|
| + EXPECT_EQ(1u, v4->size());
|
| +
|
| + // Check value3 again.
|
| + EXPECT_EQ(2u, (*v4)[0].get_size());
|
| + EXPECT_EQ(Type::SEQUENCE, (*v4)[0].get_type());
|
| + v3 = (*v4)[0].get_value().sequence;
|
| + EXPECT_EQ(2u, v3->size());
|
| + CheckUuidValue((*v3)[0], kServiceUuid);
|
| + CheckIntValue((*v3)[1], 0x1337);
|
| +}
|
| +
|
| +} // namespace bluez
|
|
|