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

Commit a449173b authored by Chris Manton's avatar Chris Manton Committed by Andre Eisenbach
Browse files

property api unification, naming and testing

parent 54cc1bac
Loading
Loading
Loading
Loading
+41 −14
Original line number Diff line number Diff line
@@ -24,27 +24,54 @@

#include "btcore/include/device_class.h"

// Copies an array of consecutive properties of |count| to a newly
// allocated array. |properties| must not be NULL.
bt_property_t *property_copy_array(const bt_property_t *properties, size_t count);

// Copies |src| to |dest|. Returns the value of |dest|.
// |src| and |dest| must not be NULL.
bt_property_t *property_copy(bt_property_t *dest, const bt_property_t *src);

// Returns true if the value of the two properties |p1| and |p2| are equal.
// |p1| and |p2| must not be NULL.
bool property_equals(const bt_property_t *p1, const bt_property_t *p2);

// Property resource allocations. Caller is expected to free |property|
// using |property_free| or |property_free_array|.
// Parameter must not be NULL. A copy of the parameter is made and
// stored in the property.
bt_property_t *property_new_addr(const bt_bdaddr_t *addr);
bt_property_t *property_new_device_class(const bt_device_class_t *dc);
bt_property_t *property_new_device_type(bt_device_type_t *device_type);
bt_property_t *property_new_discovery_timeout(uint32_t *timeout);
bt_property_t *property_new_device_type(bt_device_type_t device_type);
bt_property_t *property_new_discovery_timeout(const uint32_t timeout);
bt_property_t *property_new_name(const char *name);
bt_property_t *property_new_rssi(int8_t *rssi);
bt_property_t *property_new_rssi(const int8_t rssi);
bt_property_t *property_new_scan_mode(bt_scan_mode_t scan_mode);
bt_property_t *property_new_uuids(const bt_uuid_t *uuid, size_t count);

const char *property_extract_name(const bt_property_t *property);

const bt_bdaddr_t *property_extract_bdaddr(const bt_property_t *property);
const bt_bdname_t *property_extract_bdname(const bt_property_t *property);
const bt_device_class_t *property_extract_device_class(const bt_property_t *property);
const bt_device_type_t *property_extract_device_type(const bt_property_t *property);
int32_t property_extract_remote_rssi(const bt_property_t *property);
const bt_uuid_t *property_extract_uuid(const bt_property_t *property);

bool property_equals(const bt_property_t *p1, const bt_property_t *p2);

// Property resource frees both property and value.
void property_free(bt_property_t *property);
void property_free_array(bt_property_t *properties, size_t count);

// Value check convenience methods. The contents of the property are
// checked for the respective validity and returns true, false otherwise.
// |property| must not be NULL.
bool property_is_addr(const bt_property_t *property);
bool property_is_device_class(const bt_property_t *property);
bool property_is_device_type(const bt_property_t *property);
bool property_is_discovery_timeout(const bt_property_t *property);
bool property_is_name(const bt_property_t *property);
bool property_is_rssi(const bt_property_t *property);
bool property_is_scan_mode(const bt_property_t *property);
bool property_is_uuids(const bt_property_t *property);

// Value conversion convenience methods. The contents of the property are
// properly typed and returned to the caller. |property| must not be NULL.
const bt_bdaddr_t *property_as_addr(const bt_property_t *property);
const bt_device_class_t *property_as_device_class(const bt_property_t *property);
bt_device_type_t property_as_device_type(const bt_property_t *property);
uint32_t property_as_discovery_timeout(const bt_property_t *property);
const bt_bdname_t *property_as_name(const bt_property_t *property);
int8_t property_as_rssi(const bt_property_t *property);
bt_scan_mode_t property_as_scan_mode(const bt_property_t *property);
const bt_uuid_t *property_as_uuids(const bt_property_t *property, size_t *count);
+123 −157
Original line number Diff line number Diff line
@@ -17,10 +17,13 @@
 ******************************************************************************/

#include <assert.h>
#include "osi/include/allocator.h"
#include "btcore/include/property.h"
#include "btcore/include/bdaddr.h"
#include "btcore/include/device_class.h"
#include "btcore/include/property.h"
#include "btcore/include/uuid.h"
#include "osi/include/allocator.h"

static bt_property_t *property_new_(void *val, size_t len, bt_property_type_t type);

bt_property_t *property_copy_array(const bt_property_t *properties, size_t count) {
  assert(properties != NULL);
@@ -44,214 +47,177 @@ bt_property_t *property_copy(bt_property_t *dest, const bt_property_t *src) {
  return (bt_property_t *)memcpy(dest, src, sizeof(bt_property_t));
}

bt_property_t *property_new_name(const char *name) {
  assert(name != NULL);

  bt_property_t *property = osi_calloc(sizeof(bt_property_t));
  assert(property != NULL);

  bt_bdname_t *bdname = osi_calloc(sizeof(bt_bdname_t));
  assert(bdname != NULL);
  strlcpy((char *)bdname->name, name, sizeof(bdname->name));
bool property_equals(const bt_property_t *p1, const bt_property_t *p2) {
  // Two null properties are not the same. May need to revisit that
  // decision when we have a test case that exercises that condition.
  if (!p1 || !p2 || p1->type != p2->type) {
    return false;
  }

  property->type = BT_PROPERTY_BDNAME;
  property->val = (void *)bdname;
  property->len = sizeof(bt_bdname_t);
  // Although the Bluetooth name is a 249-byte array, the implementation
  // treats it like a variable-length array with its size specified in the
  // property's `len` field. We special-case the equivalence of BDNAME
  // types here by truncating the larger, zero-padded name to its string
  // length and comparing against the shorter name.
  //
  // Note: it may be the case that both strings are zero-padded but that
  // hasn't come up yet so this implementation doesn't handle it.
  if (p1->type == BT_PROPERTY_BDNAME && p1->len != p2->len) {
    const bt_property_t *shorter = p1, *longer = p2;
    if (p1->len > p2->len) {
      shorter = p2;
      longer = p1;
    }
    return strlen((const char *)longer->val) == (size_t)shorter->len && !memcmp(longer->val, shorter->val, shorter->len);
  }

  return property;
  return p1->len == p2->len && !memcmp(p1->val, p2->val, p1->len);
}

bt_property_t *property_new_addr(const bt_bdaddr_t *addr) {
  assert(addr != NULL);

  bt_property_t *property = osi_calloc(sizeof(bt_property_t));
  assert(property != NULL);

  bt_bdaddr_t *bdaddr = osi_calloc(sizeof(bt_bdaddr_t));
  assert(bdaddr != NULL);
  bdaddr_copy(bdaddr, addr);

  property->type = BT_PROPERTY_BDADDR;
  property->val = (void *)bdaddr;
  property->len = sizeof(bt_bdaddr_t);

  return property;
  return property_new_((void *)addr, sizeof(bt_bdaddr_t), BT_PROPERTY_BDADDR);
}

bt_property_t *property_new_device_class(const bt_device_class_t *dc) {
  assert(dc != NULL);
  return property_new_((void *)dc, sizeof(bt_device_class_t), BT_PROPERTY_CLASS_OF_DEVICE);
}

  bt_property_t *property = osi_calloc(sizeof(bt_property_t));
  assert(property != NULL);
bt_property_t *property_new_device_type(bt_device_type_t type) {
  return property_new_((void *)&type, sizeof(bt_device_type_t), BT_PROPERTY_TYPE_OF_DEVICE);
}

  bt_device_class_t *device_class = osi_calloc(sizeof(bt_device_class_t));
  assert(device_class != NULL);
  device_class_copy(device_class, dc);
bt_property_t *property_new_discovery_timeout(const uint32_t timeout) {
  return property_new_((void *)&timeout, sizeof(uint32_t), BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT);
}

  property->type = BT_PROPERTY_CLASS_OF_DEVICE;
  property->val = (void *)device_class;
  property->len = sizeof(bt_device_class_t);
bt_property_t *property_new_name(const char *name) {
  assert(name != NULL);
  return property_new_((void *)name, sizeof(bt_bdname_t), BT_PROPERTY_BDNAME);
}

  return property;
bt_property_t *property_new_rssi(int8_t rssi) {
  return property_new_((void *)&rssi, sizeof(int8_t), BT_PROPERTY_REMOTE_RSSI);
}

bt_property_t *property_new_device_type(bt_device_type_t *type) {
  assert(type != NULL);
bt_property_t *property_new_scan_mode(bt_scan_mode_t scan_mode) {
  return property_new_((void *)&scan_mode, sizeof(bt_scan_mode_t), BT_PROPERTY_ADAPTER_SCAN_MODE);
}

  bt_property_t *property = osi_calloc(sizeof(bt_property_t));
  assert(property != NULL);
bt_property_t *property_new_uuids(const bt_uuid_t *uuid, size_t count) {
  assert(uuid != NULL);
  return property_new_((void *)uuid, sizeof(bt_uuid_t) * count, BT_PROPERTY_UUIDS);
}

  bt_device_type_t *device_type = (bt_device_type_t *)osi_calloc(sizeof(bt_device_type_t));
  assert(device_type != NULL);
  *device_type = *type;
void property_free(bt_property_t *property) {
  property_free_array(property, 1);
}

  property->type = BT_PROPERTY_TYPE_OF_DEVICE;
  property->val = (void *)device_type;
  property->len = sizeof(bt_device_type_t);
void property_free_array(bt_property_t *properties, size_t count) {
  if (properties == NULL)
    return;

  return property;
  for (size_t i = 0; i < count; ++i) {
    osi_free(properties[i].val);
  }

bt_property_t *property_new_rssi(int8_t *rssi) {
  assert(rssi != NULL);
  osi_free(properties);
}

  bt_property_t *property = osi_calloc(sizeof(bt_property_t));
bool property_is_addr(const bt_property_t *property) {
  assert(property != NULL);

  int *val = (int *)osi_calloc(sizeof(rssi));
  assert(val != NULL);
  *val = *rssi;

  property->type = BT_PROPERTY_REMOTE_RSSI;
  property->val = (void *)val;
  property->len = sizeof(int);

  return property;
  return property->type == BT_PROPERTY_BDADDR;
}

bt_property_t *property_new_discovery_timeout(uint32_t *timeout) {
  assert(timeout != NULL);

  bt_property_t *property = osi_calloc(sizeof(bt_property_t));
bool property_is_device_class(const bt_property_t *property) {
  assert(property != NULL);

  uint32_t *val = osi_calloc(sizeof(uint32_t));
  assert(val != NULL);
  *val = *timeout;

  property->type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT;
  property->val = val;
  property->len = sizeof(uint32_t);

  return property;
  return property->type == BT_PROPERTY_CLASS_OF_DEVICE;
}

bt_property_t *property_new_scan_mode(bt_scan_mode_t scan_mode) {
  bt_scan_mode_t *val = osi_malloc(sizeof(bt_scan_mode_t));
  bt_property_t *property = osi_malloc(sizeof(bt_property_t));

  property->type = BT_PROPERTY_ADAPTER_SCAN_MODE;
  property->val = val;
  property->len = sizeof(bt_scan_mode_t);

  *val = scan_mode;

  return property;
bool property_is_device_type(const bt_property_t *property) {
  assert(property != NULL);
  return property->type == BT_PROPERTY_TYPE_OF_DEVICE;
}

// Warning: not thread safe.
const char *property_extract_name(const bt_property_t *property) {
  static char name[250] = { 0 };
  if (!property || property->type != BT_PROPERTY_BDNAME || !property->val) {
    return NULL;
bool property_is_discovery_timeout(const bt_property_t *property) {
  assert(property != NULL);
  return property->type == BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT;
}

  strncpy(name, (const char *)((bt_bdname_t *)property->val)->name, property->len);
  name[sizeof(name) - 1] = '\0';

  return name;
bool property_is_name(const bt_property_t *property) {
  assert(property != NULL);
  return property->type == BT_PROPERTY_BDNAME;
}

const bt_bdaddr_t *property_extract_bdaddr(const bt_property_t *property) {
  if (!property || property->type != BT_PROPERTY_BDADDR || !property->val) {
    return NULL;
  }
  return (const bt_bdaddr_t *)property->val;
bool property_is_rssi(const bt_property_t *property) {
  assert(property != NULL);
  return property->type == BT_PROPERTY_REMOTE_RSSI;
}

const bt_bdname_t *property_extract_bdname(const bt_property_t *property) {
  if (!property || property->type != BT_PROPERTY_BDNAME || !property->val) {
    return NULL;
bool property_is_scan_mode(const bt_property_t *property) {
  assert(property != NULL);
  return property->type == BT_PROPERTY_ADAPTER_SCAN_MODE;
}
  return (const bt_bdname_t *)property->val;

bool property_is_uuids(const bt_property_t *property) {
  assert(property != NULL);
  return property->type == BT_PROPERTY_UUIDS;
}

const bt_device_class_t *property_extract_device_class(const bt_property_t *property) {
  if (!property || property->type != BT_PROPERTY_CLASS_OF_DEVICE || !property->val) {
    return 0;
// Convenience conversion methods to property values
const bt_bdaddr_t *property_as_addr(const bt_property_t *property) {
  assert(property_is_addr(property));
  return (const bt_bdaddr_t *)property->val;
}

const bt_device_class_t *property_as_device_class(const bt_property_t *property) {
  assert(property_is_device_class(property));
  return (const bt_device_class_t *)property->val;
}

const bt_device_type_t *property_extract_device_type(const bt_property_t *property) {
  if (!property || property->type != BT_PROPERTY_TYPE_OF_DEVICE || !property->val) {
    return NULL;
  }
  return (const bt_device_type_t*)property->val;
bt_device_type_t property_as_device_type(const bt_property_t *property) {
  assert(property_is_device_type(property));
  return *(const bt_device_type_t *)property->val;
}

int32_t property_extract_remote_rssi(const bt_property_t *property) {
  if (!property || property->type != BT_PROPERTY_REMOTE_RSSI || !property->val) {
    return 0;
  }
  return *(const int32_t*)property->val;
uint32_t property_as_discovery_timeout(const bt_property_t *property) {
  assert(property_is_discovery_timeout(property));
  return *(const uint32_t *)property->val;
}

const bt_uuid_t *property_extract_uuid(const bt_property_t *property) {
  if (!property || property->type != BT_PROPERTY_UUIDS || !property->val) {
    return NULL;
  }
  return (const bt_uuid_t *)property->val;
const bt_bdname_t *property_as_name(const bt_property_t *property) {
  assert(property_is_name(property));
  return (const bt_bdname_t *)property->val;
}

bool property_equals(const bt_property_t *p1, const bt_property_t *p2) {
  // Two null properties are not the same. May need to revisit that
  // decision when we have a test case that exercises that condition.
  if (!p1 || !p2 || p1->type != p2->type) {
    return false;
int8_t property_as_rssi(const bt_property_t *property) {
  assert(property_is_rssi(property));
  return *(const int8_t *)property->val;
}

  // Although the Bluetooth name is a 249-byte array, the implementation
  // treats it like a variable-length array with its size specified in the
  // property's `len` field. We special-case the equivalence of BDNAME
  // types here by truncating the larger, zero-padded name to its string
  // length and comparing against the shorter name.
  //
  // Note: it may be the case that both strings are zero-padded but that
  // hasn't come up yet so this implementation doesn't handle it.
  if (p1->type == BT_PROPERTY_BDNAME && p1->len != p2->len) {
    const bt_property_t *shorter = p1, *longer = p2;
    if (p1->len > p2->len) {
      shorter = p2;
      longer = p1;
    }
    return strlen((const char *)longer->val) == (size_t)shorter->len && !memcmp(longer->val, shorter->val, shorter->len);
bt_scan_mode_t property_as_scan_mode(const bt_property_t *property) {
  assert(property_is_scan_mode(property));
  return *(const bt_scan_mode_t *)property->val;
}

  return p1->len == p2->len && !memcmp(p1->val, p2->val, p1->len);
const bt_uuid_t *property_as_uuids(const bt_property_t *property, size_t *count) {
  assert(property_is_uuids(property));
  *count = sizeof(bt_uuid_t) / property->len;
  return (const bt_uuid_t *)property->val;
}

void property_free(bt_property_t *property) {
  property_free_array(property, 1);
}
static bt_property_t *property_new_(void *val, size_t len, bt_property_type_t type) {
  bt_property_t *property = osi_calloc(sizeof(bt_property_t));
  assert(property != NULL);

void property_free_array(bt_property_t *properties, size_t count) {
  if (properties == NULL)
    return;
  property->val = osi_malloc(len);
  assert(property->val != NULL);

  for (size_t i = 0; i < count; ++i) {
    osi_free(properties[i].val);
  }
  memcpy(property->val, val, len);

  osi_free(properties);
  property->type = type;
  property->len = len;

  return property;
}
+210 −2
Original line number Diff line number Diff line
@@ -21,19 +21,227 @@
#include "osi/test/AllocationTestHarness.h"

extern "C" {
#include "btcore/include/device_class.h"
#include "btcore/include/property.h"
}  // "C"

class PropertyTest : public AllocationTestHarness {};

TEST_F(PropertyTest, addr) {
  bt_bdaddr_t addr0 = {{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}};
  bt_property_t *property = property_new_addr(&addr0);

  EXPECT_EQ(addr0.address[0], ((uint8_t*)property->val)[0]);
  EXPECT_EQ(addr0.address[1], ((uint8_t*)property->val)[1]);
  EXPECT_EQ(addr0.address[2], ((uint8_t*)property->val)[2]);
  EXPECT_EQ(addr0.address[3], ((uint8_t*)property->val)[3]);
  EXPECT_EQ(addr0.address[4], ((uint8_t*)property->val)[4]);
  EXPECT_EQ(addr0.address[5], ((uint8_t*)property->val)[5]);
  EXPECT_EQ(BT_PROPERTY_BDADDR, property->type);
  EXPECT_EQ((int)sizeof(bt_bdaddr_t), property->len);

  const bt_bdaddr_t *addr1 = property_as_addr(property);
  EXPECT_EQ(addr0.address[0], addr1->address[0]);

  property_free(property);
}

TEST_F(PropertyTest, device_class) {
  bt_device_class_t dc0 = {{ 0x01, 0x23, 0x45 }};
  bt_property_t *property = property_new_device_class(&dc0);

  const bt_device_class_t *dc1 = property_extract_device_class(property);
  EXPECT_EQ(dc0._[0], ((uint8_t*)property->val)[0]);
  EXPECT_EQ(dc0._[1], ((uint8_t*)property->val)[1]);
  EXPECT_EQ(dc0._[2], ((uint8_t*)property->val)[2]);
  EXPECT_EQ(BT_PROPERTY_CLASS_OF_DEVICE, property->type);
  EXPECT_EQ((int)sizeof(bt_device_class_t), property->len);

  const bt_device_class_t *dc1 = property_as_device_class(property);
  int dc_int = device_class_to_int(dc1);
  EXPECT_EQ(0x452301, dc_int);

  property_free(property);
}

TEST_F(PropertyTest, device_type) {
  bt_device_type_t dt0 = (bt_device_type_t)1;
  bt_property_t *property = property_new_device_type(dt0);

  EXPECT_EQ((int)dt0, *(int*)property->val);
  EXPECT_EQ(BT_PROPERTY_TYPE_OF_DEVICE, property->type);
  EXPECT_EQ((int)sizeof(bt_device_type_t), property->len);

  bt_device_type_t dt1 = property_as_device_type(property);
  EXPECT_EQ(1, (int)dt1);

  property_free(property);
}

TEST_F(PropertyTest, discovery_timeout) {
  uint32_t timeout0 = 12345;
  bt_property_t *property = property_new_discovery_timeout(timeout0);

  EXPECT_EQ(timeout0, *(uint32_t *)property->val);
  EXPECT_EQ(BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT, property->type);
  EXPECT_EQ((int)sizeof(uint32_t), property->len);

  uint32_t timeout1 = property_as_discovery_timeout(property);
  EXPECT_EQ(timeout0, timeout1);

  property_free(property);
}

TEST_F(PropertyTest, name) {
  const char *name0 = "My btcore name";
  bt_property_t *property = property_new_name(name0);

  EXPECT_EQ(0, strcmp((char *)name0, (char *)property->val));
  EXPECT_EQ(BT_PROPERTY_BDNAME, property->type);
  EXPECT_EQ((int)sizeof(bt_bdname_t), property->len);

  const bt_bdname_t *name1 = property_as_name(property);
  EXPECT_EQ(0, strcmp((char *)name0, (char *)name1->name));

  property_free(property);
}

TEST_F(PropertyTest, rssi) {
  int8_t rssi0 = -56;
  bt_property_t *property = property_new_rssi(rssi0);

  EXPECT_EQ(*(int8_t *)property->val, rssi0);
  EXPECT_EQ(BT_PROPERTY_REMOTE_RSSI, property->type);
  EXPECT_EQ((int)sizeof(int8_t), property->len);

  int8_t rss1 = property_as_rssi(property);
  EXPECT_EQ(rssi0, rss1);

  property_free(property);
}

TEST_F(PropertyTest, scan_mode) {
  bt_scan_mode_t mode0 = (bt_scan_mode_t)3;
  bt_property_t *property = property_new_scan_mode(mode0);

  EXPECT_EQ(*(int *)property->val, mode0);
  EXPECT_EQ(BT_PROPERTY_ADAPTER_SCAN_MODE, property->type);
  EXPECT_EQ((int)sizeof(int), property->len);

  bt_scan_mode_t mode1 = property_as_scan_mode(property);
  EXPECT_EQ((int)mode0, (int)mode1);

  property_free(property);
}

TEST_F(PropertyTest, uuids) {
  bt_uuid_t uuid0 = {
    {
      0x00, 0x11, 0x22, 0x33,
      0x44, 0x55, 0x66, 0x77,
      0x88, 0x99, 0xaa, 0xbb,
      0xcc, 0xdd, 0xee, 0xff,
    }
  };
  bt_property_t *property = property_new_uuids(&uuid0, 1);

  EXPECT_EQ(0, strcmp((const char *)uuid0.uu, (char *)property->val));
  EXPECT_EQ(BT_PROPERTY_UUIDS, property->type);
  EXPECT_EQ((int)sizeof(bt_uuid_t), property->len);

  size_t uuid_cnt1;
  const bt_uuid_t *uuid1 = property_as_uuids(property, &uuid_cnt1);
  EXPECT_EQ(0, memcmp(uuid1->uu, uuid1->uu, sizeof(bt_uuid_t)));

  property_free(property);
}

TEST_F(PropertyTest, copy) {
  {
    bt_uuid_t uuids[] = {
      {{
         0x00, 0x11, 0x22, 0x33,
         0x44, 0x55, 0x66, 0x77,
         0x88, 0x99, 0xaa, 0xbb,
         0xcc, 0xdd, 0xee, 0xff,
       }},
      {{
         0xf0, 0xe1, 0xd2, 0xc3,
         0xf4, 0xe5, 0xd6, 0xc7,
         0xf8, 0xe9, 0xda, 0xcb,
         0xfc, 0xed, 0xde, 0xcf,
       }},
    };

    bt_property_t *property0 = property_new_uuids(uuids, sizeof(bt_uuid_t)/sizeof(uuids));

    bt_property_t property1;
    property_copy(&property1, property0);
    EXPECT_TRUE(property_equals(property0, &property1));

    property_free(property0);
  }
}

TEST_F(PropertyTest, equals) {
  {
    bt_bdaddr_t addr0 = {{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}};
    bt_property_t *property0 = property_new_addr(&addr0);

    bt_device_class_t dc0 = {{ 0x01, 0x23, 0x45 }};
    bt_property_t *property1 = property_new_device_class(&dc0);

    EXPECT_FALSE(property_equals(property0, property1));

    property_free(property0);
    property_free(property1);
  }

  {
    bt_bdaddr_t addr = {{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}};
    bt_property_t *property0 = property_new_addr(&addr);
    bt_property_t *property1 = property_new_addr(&addr);

    EXPECT_TRUE(property_equals(property0, property1));

    property_free(property0);
    property_free(property1);
  }

  {
    bt_bdaddr_t addr0 = {{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}};
    bt_property_t *property0 = property_new_addr(&addr0);

    bt_bdaddr_t addr1 = {{0x1, 0x2, 0x3, 0x4, 0x5, 0xff}};
    bt_property_t *property1 = property_new_addr(&addr1);

    EXPECT_FALSE(property_equals(property0, property1));

    property_free(property0);
    property_free(property1);
  }

  {
    const char *name0 = "My btcore name";
    bt_property_t *property0 = property_new_name(name0);

    const char *name1 = "My btcore name";
    bt_property_t *property1 = property_new_name(name1);

    EXPECT_TRUE(property_equals(property0, property1));

    property_free(property0);
    property_free(property1);
  }

  {
    const char *name0 = "My btcore name";
    bt_property_t *property0 = property_new_name(name0);

    const char *name1 = "My btcore name     ";
    bt_property_t *property1 = property_new_name(name1);

    EXPECT_FALSE(property_equals(property0, property1));

    property_free(property0);
    property_free(property1);
  }
}
+2 −2
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ bool adapter_set_name() {
  TASSERT(error == BT_STATUS_SUCCESS, "Error setting device name.");
  TASSERT(adapter_get_property_count() == 1, "Expected 1 adapter property change, found %d instead.", adapter_get_property_count());
  TASSERT(adapter_get_property(BT_PROPERTY_BDNAME), "The Bluetooth name property did not change.");
  TASSERT(property_equals(adapter_get_property(BT_PROPERTY_BDNAME), name), "Bluetooth name '%s' does not match test value", property_extract_name(adapter_get_property(BT_PROPERTY_BDNAME)));
  TASSERT(property_equals(adapter_get_property(BT_PROPERTY_BDNAME), name), "Bluetooth name '%s' does not match test value", property_as_name(adapter_get_property(BT_PROPERTY_BDNAME))->name);

  property_free(name);

@@ -68,7 +68,7 @@ bool adapter_get_name() {
  TASSERT(error == BT_STATUS_SUCCESS, "Error getting device name.");
  TASSERT(adapter_get_property_count() == 1, "Expected 1 adapter property change, found %d instead.", adapter_get_property_count());
  TASSERT(adapter_get_property(BT_PROPERTY_BDNAME), "The Bluetooth name property did not change.");
  TASSERT(property_equals(adapter_get_property(BT_PROPERTY_BDNAME), name), "Bluetooth name '%s' does not match test value", property_extract_name(adapter_get_property(BT_PROPERTY_BDNAME)));
  TASSERT(property_equals(adapter_get_property(BT_PROPERTY_BDNAME), name), "Bluetooth name '%s' does not match test value", property_as_name(adapter_get_property(BT_PROPERTY_BDNAME))->name);

  property_free(name);
  return true;
+21 −18

File changed.

Preview size limit exceeded, changes collapsed.

Loading