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

Commit 1f3608d1 authored by Arman Uguray's avatar Arman Uguray
Browse files

service: Fix clang warnings in uuid_test.cpp

This CL fixes some clang compile warnings and errors and style issues in
service/uuid_test.cpp

Bug: none
Change-Id: I2d1ecf6e21fe4d6b1741f2a113ed5834518a29c6
parent c15b685a
Loading
Loading
Loading
Loading
+51 −53
Original line number Diff line number Diff line
@@ -23,103 +23,101 @@

using namespace bluetooth;

struct UuidTest : public ::testing::Test {
  typedef std::array<uint8_t, Uuid::kUuid128Octets> UuidData;
namespace {

  UuidTest()
      : kBtSigBaseUuid({0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
              0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb})
  {}

  const UuidData kBtSigBaseUuid;
const std::array<uint8_t, Uuid::kUuid128Octets> kBtSigBaseUuid = {
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
      0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb, }
};

}  // namespace

// Verify that an uninitialized Uuid is equal
// To the BT SIG Base UUID.
TEST_F(UuidTest, DefaultUuid) {
TEST(UuidTest, DefaultUuid) {
  Uuid uuid;
  ASSERT_TRUE(uuid.GetFullBigEndian() == kBtSigBaseUuid);
}

// Verify that we initialize a 16-bit UUID in a
// way consistent with how we read it.
TEST_F(UuidTest, Init16Bit) {
  auto My16BitUuid = kBtSigBaseUuid;
  My16BitUuid[2] = 0xde;
  My16BitUuid[3] = 0xad;
  Uuid uuid(Uuid::Uuid16Bit({0xde, 0xad}));
  ASSERT_TRUE(uuid.GetFullBigEndian() == My16BitUuid);
TEST(UuidTest, Init16Bit) {
  auto my_uuid_16 = kBtSigBaseUuid;
  my_uuid_16[2] = 0xde;
  my_uuid_16[3] = 0xad;
  Uuid uuid(Uuid::Uuid16Bit({{ 0xde, 0xad }}));
  ASSERT_TRUE(uuid.GetFullBigEndian() == my_uuid_16);
}

// Verify that we initialize a 16-bit UUID in a
// way consistent with how we read it.
TEST_F(UuidTest, Init16BitString) {
  auto My16BitUuid = kBtSigBaseUuid;
  My16BitUuid[2] = 0xde;
  My16BitUuid[3] = 0xad;
TEST(UuidTest, Init16BitString) {
  auto my_uuid_16 = kBtSigBaseUuid;
  my_uuid_16[2] = 0xde;
  my_uuid_16[3] = 0xad;
  Uuid uuid("dead");
  ASSERT_TRUE(uuid.GetFullBigEndian() == My16BitUuid);
  ASSERT_TRUE(uuid.GetFullBigEndian() == my_uuid_16);
}


// Verify that we initialize a 32-bit UUID in a
// way consistent with how we read it.
TEST_F(UuidTest, Init32Bit) {
  auto My32BitUuid = kBtSigBaseUuid;
  My32BitUuid[0] = 0xde;
  My32BitUuid[1] = 0xad;
  My32BitUuid[2] = 0xbe;
  My32BitUuid[3] = 0xef;
  Uuid uuid(Uuid::Uuid32Bit({0xde, 0xad, 0xbe, 0xef}));
  ASSERT_TRUE(uuid.GetFullBigEndian() == My32BitUuid);
TEST(UuidTest, Init32Bit) {
  auto my_uuid_32 = kBtSigBaseUuid;
  my_uuid_32[0] = 0xde;
  my_uuid_32[1] = 0xad;
  my_uuid_32[2] = 0xbe;
  my_uuid_32[3] = 0xef;
  Uuid uuid(Uuid::Uuid32Bit({{ 0xde, 0xad, 0xbe, 0xef }}));
  ASSERT_TRUE(uuid.GetFullBigEndian() == my_uuid_32);
}

// Verify correct reading of a 32-bit UUID initialized from string.
TEST_F(UuidTest, Init32BitString) {
  auto My32BitUuid = kBtSigBaseUuid;
  My32BitUuid[0] = 0xde;
  My32BitUuid[1] = 0xad;
  My32BitUuid[2] = 0xbe;
  My32BitUuid[3] = 0xef;
TEST(UuidTest, Init32BitString) {
  auto my_uuid_32 = kBtSigBaseUuid;
  my_uuid_32[0] = 0xde;
  my_uuid_32[1] = 0xad;
  my_uuid_32[2] = 0xbe;
  my_uuid_32[3] = 0xef;
  Uuid uuid("deadbeef");
  ASSERT_TRUE(uuid.GetFullBigEndian() == My32BitUuid);
  ASSERT_TRUE(uuid.GetFullBigEndian() == my_uuid_32);
}

// Verify that we initialize a 128-bit UUID in a
// way consistent with how we read it.
TEST_F(UuidTest, Init128Bit) {
  auto My128BitUuid = kBtSigBaseUuid;
  for (int i = 0; i < static_cast<int>(My128BitUuid.size()); ++i) {
    My128BitUuid[i] = i;
TEST(UuidTest, Init128Bit) {
  auto my_uuid_128 = kBtSigBaseUuid;
  for (int i = 0; i < static_cast<int>(my_uuid_128.size()); ++i) {
    my_uuid_128[i] = i;
  }

  Uuid uuid(My128BitUuid);
  ASSERT_TRUE(uuid.GetFullBigEndian() == My128BitUuid);
  Uuid uuid(my_uuid_128);
  ASSERT_TRUE(uuid.GetFullBigEndian() == my_uuid_128);
}

// Verify that we initialize a 128-bit UUID in a
// way consistent with how we read it as LE.
TEST_F(UuidTest, Init128BitLittleEndian) {
  auto My128BitUuid = kBtSigBaseUuid;
  for (int i = 0; i < static_cast<int>(My128BitUuid.size()); ++i) {
    My128BitUuid[i] = i;
TEST(UuidTest, Init128BitLittleEndian) {
  auto my_uuid_128 = kBtSigBaseUuid;
  for (int i = 0; i < static_cast<int>(my_uuid_128.size()); ++i) {
    my_uuid_128[i] = i;
  }

  Uuid uuid(My128BitUuid);
  std::reverse(My128BitUuid.begin(), My128BitUuid.end());
  ASSERT_TRUE(uuid.GetFullLittleEndian() == My128BitUuid);
  Uuid uuid(my_uuid_128);
  std::reverse(my_uuid_128.begin(), my_uuid_128.end());
  ASSERT_TRUE(uuid.GetFullLittleEndian() == my_uuid_128);
}

// Verify that we initialize a 128-bit UUID in a
// way consistent with how we read it.
TEST_F(UuidTest, Init128BitString) {
  auto My128BitUuid = kBtSigBaseUuid;
  for (int i = 0; i < static_cast<int>(My128BitUuid.size()); ++i) {
    My128BitUuid[i] = i;
TEST(UuidTest, Init128BitString) {
  auto my_uuid_128 = kBtSigBaseUuid;
  for (int i = 0; i < static_cast<int>(my_uuid_128.size()); ++i) {
    my_uuid_128[i] = i;
  }

  std::string uuid_text("000102030405060708090A0B0C0D0E0F");
  ASSERT_TRUE(uuid_text.size() == (16 * 2));
  Uuid uuid(uuid_text);
  ASSERT_TRUE(uuid.GetFullBigEndian() == My128BitUuid);
  ASSERT_TRUE(uuid.GetFullBigEndian() == my_uuid_128);
}