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

Commit 4accb24f authored by Chris Manton's avatar Chris Manton
Browse files

IA2: Introduce bta_dm_gatt_client_test

Bug: 298523766
Test: atest bt_host_test_bta
Change-Id: I8e8e260ada3f90e2b77b2a6aba756effa613aa92

Change-Id: Ia9de400cb6b3d23c4202cbb88101ddadf8c535f6
parent e02532f0
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -19,11 +19,11 @@
#include <base/strings/stringprintf.h>

#include <cstdint>
#include <cstring>
#include <string>
#include <vector>

#include "bta/include/bta_gatt_api.h"
#include "gd/common/strings.h"
#include "osi/include/log.h"
#include "stack/btm/btm_int_types.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"
@@ -121,3 +121,16 @@ void DumpsysBtaDmGattClient(int fd) {
void bluetooth::testing::set_gatt_interface(const gatt_interface_t& interface) {
  *gatt_interface = interface;
}

namespace bluetooth {
namespace legacy {
namespace testing {

std::vector<bluetooth::common::TimestampedEntry<std::string>>
PullCopyOfGattHistory() {
  return gatt_history_.Pull();
}

}  // namespace testing
}  // namespace legacy
}  // namespace bluetooth
+70 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <base/strings/stringprintf.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <sys/socket.h>

#include <string>

#include "bta/dm/bta_dm_gatt_client.h"
#include "gd/common/circular_buffer.h"
#include "stack/btm/btm_int_types.h"

using namespace bluetooth::common;

// Test hooks
namespace bluetooth {
namespace legacy {
namespace testing {

std::vector<TimestampedEntry<std::string>> PullCopyOfGattHistory();

}  // namespace testing
}  // namespace legacy
}  // namespace bluetooth

class BtaDiscTest : public testing::Test {
 protected:
  void SetUp() override {}

  void TearDown() override {}
};

TEST_F(BtaDiscTest, nop) {}

TEST_F(BtaDiscTest, gatt_history_callback) {
  std::array<std::string, 3> a = {
      "ThisIsATest 0",
      "ThisIsATest 1",
      "ThisIsATest 2",
  };

  // C string
  gatt_history_callback(base::StringPrintf("%s", a[0].c_str()));
  // Cpp string
  gatt_history_callback(a[1]);
  // Third entry for "fun"
  gatt_history_callback(base::StringPrintf("%s", a[2].c_str()));

  std::vector<bluetooth::common::TimestampedEntry<std::string>> history =
      bluetooth::legacy::testing::PullCopyOfGattHistory();
  ASSERT_EQ(3UL, history.size());
  ASSERT_STREQ(a[0].c_str(), history[0].entry.c_str());
  ASSERT_STREQ(a[1].c_str(), history[1].entry.c_str());
  ASSERT_STREQ(a[2].c_str(), history[2].entry.c_str());
}