Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3d5fceda authored by Chris Manton's avatar Chris Manton
Browse files

gd_unit_test: Extend Address and AddressWithType

Bug: 245578454
Test: atest bluetooth_test_gd_unit64
Flag: EXEMPT, Test Infrastructure

Change-Id: I4d08e5e2fe23f28006417b527d21f58771e00a87
parent 0681d4cf
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -246,3 +246,13 @@ TEST(AddressTest, ToStringForLoggingTestOutputUnderDebuggablePropAndInitFlag) {
  std::string ret2 = addr.ToRedactedStringForLogging();
  ASSERT_STREQ(ret2.c_str(), redacted_loggable_str.c_str());
}

TEST(AddressTest, Inequalities) {
  Address addr1{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
  Address addr2{{0x02, 0x03, 0x04, 0x05, 0x06, 0x07}};
  ASSERT_TRUE(addr1 < addr2);
  ASSERT_TRUE(addr2 > addr1);

  ASSERT_TRUE(addr1 <= addr1);
  ASSERT_TRUE(addr2 <= addr2);
}
+63 −0
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@
#include "hci/hci_packets.h"
#include "hci/octets.h"

using namespace bluetooth;

namespace bluetooth {
namespace hci {

@@ -247,5 +249,66 @@ TEST(AddressWithTypeTest, HashMap) {
  }
}

TEST(AddressWithTypeTest, ToFilterAcceptListAddressType) {
  {
    AddressWithType address = AddressWithType(
        Address{{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}}, AddressType::PUBLIC_DEVICE_ADDRESS);
    ASSERT_EQ(hci::FilterAcceptListAddressType::PUBLIC, address.ToFilterAcceptListAddressType());
  }

  {
    AddressWithType address = AddressWithType(
        Address{{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}}, AddressType::PUBLIC_IDENTITY_ADDRESS);
    ASSERT_EQ(hci::FilterAcceptListAddressType::PUBLIC, address.ToFilterAcceptListAddressType());
  }

  {
    AddressWithType address = AddressWithType(
        Address{{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}}, AddressType::RANDOM_DEVICE_ADDRESS);
    ASSERT_EQ(hci::FilterAcceptListAddressType::RANDOM, address.ToFilterAcceptListAddressType());
  }

  {
    AddressWithType address = AddressWithType(
        Address{{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}}, AddressType::RANDOM_IDENTITY_ADDRESS);
    ASSERT_EQ(hci::FilterAcceptListAddressType::RANDOM, address.ToFilterAcceptListAddressType());
  }
}

TEST(AddressWithTypeTest, ToPeerAddressType) {
  {
    AddressWithType address = AddressWithType(
        Address{{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}}, AddressType::PUBLIC_DEVICE_ADDRESS);
    ASSERT_EQ(hci::PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, address.ToPeerAddressType());
  }

  {
    AddressWithType address = AddressWithType(
        Address{{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}}, AddressType::PUBLIC_IDENTITY_ADDRESS);
    ASSERT_EQ(hci::PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, address.ToPeerAddressType());
  }

  {
    AddressWithType address = AddressWithType(
        Address{{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}}, AddressType::RANDOM_DEVICE_ADDRESS);
    ASSERT_EQ(hci::PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, address.ToPeerAddressType());
  }

  {
    AddressWithType address = AddressWithType(
        Address{{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}}, AddressType::RANDOM_IDENTITY_ADDRESS);
    ASSERT_EQ(hci::PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, address.ToPeerAddressType());
  }
}

TEST(AddressWithTypeTest, StringStream) {
  AddressWithType address_with_type = AddressWithType(
      Address{{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}}, AddressType::PUBLIC_DEVICE_ADDRESS);

  std::stringstream oss;
  oss << address_with_type;
  ASSERT_STREQ("66:55:44:33:22:11[PUBLIC_DEVICE_ADDRESS]", oss.str().c_str());
}

}  // namespace hci
}  // namespace bluetooth