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

Commit 842efd46 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Remove all mentions of hashmap

Change-Id: I4594c401d91c6d5e2626ca92593f0f29833844ab
parent 8fd78613
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ static_library("btcore") {
executable("net_test_btcore") {
  testonly = true
  sources = [
    "test/bdaddr_test.cc",
    "test/device_class_test.cc",
    "test/property_test.cc",
    "test/uuid_test.cc",
+0 −4
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@
#include <hardware/bluetooth.h>
#include <stdbool.h>
#include <stddef.h>
#include "osi/include/hash_functions.h"

#ifdef __cplusplus
extern "C" {
@@ -61,9 +60,6 @@ bool string_is_bdaddr(const char *string);
// false. Otherwise, it returns true. Neither |string| nor |addr| may be NULL.
bool string_to_bdaddr(const char *string, bt_bdaddr_t *addr);

// A hash function tailored for bdaddrs.
hash_index_t hash_function_bdaddr(const void *key);

#ifdef __cplusplus
}
#endif
+0 −9
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@
#include <string.h>

#include "btcore/include/bdaddr.h"
#include "osi/include/hash_functions.h"

bool bdaddr_is_empty(const bt_bdaddr_t *addr) {
  assert(addr != NULL);
@@ -92,11 +91,3 @@ bool string_to_bdaddr(const char *string, bt_bdaddr_t *addr) {

  return ret;
}

hash_index_t hash_function_bdaddr(const void *key) {
  hash_index_t hash = 5381;
  const char *bytes = (const char *)key;
  for (size_t i = 0; i < sizeof(bt_bdaddr_t); ++i)
    hash = ((hash << 5) + hash) + bytes[i];
  return hash;
}
+43 −16
Original line number Diff line number Diff line
@@ -22,27 +22,54 @@ extern "C" {
#include "btcore/include/bdaddr.h"
}

TEST(HashFunctionBdaddrTest, test_same_pointer_is_same) {
  bt_bdaddr_t test_address;
  string_to_bdaddr("12:34:56:78:9A:BC", &test_address);
static const char* test_addr = "12:34:56:78:9a:bc";
static const char* test_addr2 = "cb:a9:87:65:43:21";

  EXPECT_EQ(hash_function_bdaddr(&test_address), hash_function_bdaddr(&test_address));

TEST(BdaddrTest, test_empty) {
  bt_bdaddr_t empty;
  string_to_bdaddr("00:00:00:00:00:00", &empty);
  ASSERT_TRUE(bdaddr_is_empty(&empty));

  bt_bdaddr_t not_empty;
  string_to_bdaddr("00:00:00:00:00:01", &not_empty);
  ASSERT_FALSE(bdaddr_is_empty(&not_empty));
}

TEST(BdaddrTest, test_to_from_str) {
  char ret[19];
  bt_bdaddr_t bdaddr;
  string_to_bdaddr(test_addr, &bdaddr);

  ASSERT_EQ(0x12, bdaddr.address[0]);
  ASSERT_EQ(0x34, bdaddr.address[1]);
  ASSERT_EQ(0x56, bdaddr.address[2]);
  ASSERT_EQ(0x78, bdaddr.address[3]);
  ASSERT_EQ(0x9A, bdaddr.address[4]);
  ASSERT_EQ(0xBC, bdaddr.address[5]);

  bdaddr_to_string(&bdaddr, ret, sizeof(ret));

  ASSERT_STREQ(test_addr, ret);
}

TEST(HashFunctionBdaddrTest, test_same_value_is_same) {
  bt_bdaddr_t test_address0;
  bt_bdaddr_t test_address1;
  string_to_bdaddr("12:34:56:78:9A:BC", &test_address0);
  string_to_bdaddr("12:34:56:78:9A:BC", &test_address1);
TEST(BdaddrTest, test_equals) {
  bt_bdaddr_t bdaddr1;
  bt_bdaddr_t bdaddr2;
  bt_bdaddr_t bdaddr3;
  string_to_bdaddr(test_addr, &bdaddr1);
  string_to_bdaddr(test_addr, &bdaddr2);
  EXPECT_TRUE(bdaddr_equals(&bdaddr1, &bdaddr2));

  EXPECT_EQ(hash_function_bdaddr(&test_address0), hash_function_bdaddr(&test_address1));
  string_to_bdaddr(test_addr2, &bdaddr3);
  EXPECT_FALSE(bdaddr_equals(&bdaddr2, &bdaddr3));
}

TEST(HashFunctionBdaddrTest, test_different_value_is_different) {
  bt_bdaddr_t test_address0;
  bt_bdaddr_t test_address1;
  string_to_bdaddr("12:34:56:78:9A:BC", &test_address0);
  string_to_bdaddr("43:56:21:78:9A:BC", &test_address1);
TEST(BdaddrTest, test_copy) {
  bt_bdaddr_t bdaddr1;
  bt_bdaddr_t bdaddr2;
  string_to_bdaddr(test_addr, &bdaddr1);
  bdaddr_copy(&bdaddr2, &bdaddr1);

  EXPECT_NE(hash_function_bdaddr(&test_address0), hash_function_bdaddr(&test_address1));
  EXPECT_TRUE(bdaddr_equals(&bdaddr1, &bdaddr2));
}
 No newline at end of file
+0 −3
Original line number Diff line number Diff line
@@ -35,8 +35,6 @@ btosiCommonSrc := \
    ./src/eager_reader.c \
    ./src/fixed_queue.c \
    ./src/future.c \
    ./src/hash_functions.c \
    ./src/hash_map.c \
    ./src/hash_map_utils.cc \
    ./src/list.c \
    ./src/metrics.cc \
@@ -65,7 +63,6 @@ btosiCommonTestSrc := \
    ./test/eager_reader_test.cc \
    ./test/fixed_queue_test.cc \
    ./test/future_test.cc \
    ./test/hash_map_test.cc \
    ./test/hash_map_utils_test.cc \
    ./test/list_test.cc \
    ./test/properties_test.cc \
Loading