blob: 85fd38a77d00b58e4101d0695da420141da1551d [file] [log] [blame]
// Copyright 2018 The Fuchsia 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 "util.h"
#include "gtest/gtest.h"
namespace bt {
namespace hci {
namespace {
TEST(HCI_UtilTest, DeviceAddressFromAdvReportParsesAddress) {
StaticByteBuffer<sizeof(LEAdvertisingReportData)> buffer;
auto* report =
reinterpret_cast<LEAdvertisingReportData*>(buffer.mutable_data());
report->address = DeviceAddressBytes({0, 1, 2, 3, 4, 5});
report->address_type = LEAddressType::kPublicIdentity;
DeviceAddress address;
bool resolved;
EXPECT_TRUE(DeviceAddressFromAdvReport(*report, &address, &resolved));
EXPECT_EQ(DeviceAddress::Type::kLEPublic, address.type());
EXPECT_TRUE(resolved);
report->address_type = LEAddressType::kPublic;
EXPECT_TRUE(DeviceAddressFromAdvReport(*report, &address, &resolved));
EXPECT_EQ(DeviceAddress::Type::kLEPublic, address.type());
EXPECT_FALSE(resolved);
report->address_type = LEAddressType::kRandomIdentity;
EXPECT_TRUE(DeviceAddressFromAdvReport(*report, &address, &resolved));
EXPECT_EQ(DeviceAddress::Type::kLERandom, address.type());
EXPECT_TRUE(resolved);
report->address_type = LEAddressType::kRandom;
EXPECT_TRUE(DeviceAddressFromAdvReport(*report, &address, &resolved));
EXPECT_EQ(DeviceAddress::Type::kLERandom, address.type());
EXPECT_FALSE(resolved);
}
} // namespace
} // namespace hci
} // namespace bt