diff --git a/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp b/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp index 43cb914d80..7f89853b44 100644 --- a/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp +++ b/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp @@ -24,15 +24,14 @@ #include #include #include -#include #include #include #include #include -#include #include #include +#include #include // TODO: Remove custom logging defines from PDL packets. @@ -63,9 +62,9 @@ static constexpr uint16_t kAclHandleQcaDebugMessage = 0xedc; class ThroughputLogger { public: - ThroughputLogger(std::string task) + explicit ThroughputLogger(std::string task) : total_bytes_(0), - task_(task), + task_(std::move(task)), start_time_(std::chrono::steady_clock::now()) {} ~ThroughputLogger() { @@ -94,7 +93,7 @@ class ThroughputLogger { // The main test class for Bluetooth HAL. class BluetoothAidlTest : public ::testing::TestWithParam { public: - virtual void SetUp() override { + void SetUp() override { // currently test passthrough mode only hci = IBluetoothHci::fromBinder( SpAIBinder(AServiceManager_waitForService(GetParam().c_str()))); @@ -110,7 +109,7 @@ class BluetoothAidlTest : public ::testing::TestWithParam { ASSERT_NE(bluetooth_hci_death_recipient, nullptr); ASSERT_EQ(STATUS_OK, AIBinder_linkToDeath(hci->asBinder().get(), - bluetooth_hci_death_recipient, 0)); + bluetooth_hci_death_recipient, nullptr)); hci_cb = ndk::SharedRefBase::make(*this); ASSERT_NE(hci_cb, nullptr); @@ -131,7 +130,7 @@ class BluetoothAidlTest : public ::testing::TestWithParam { ASSERT_TRUE(future.get()); } - virtual void TearDown() override { + void TearDown() override { ALOGI("TearDown"); // Should not be checked in production code ASSERT_TRUE(hci->close().isOk()); @@ -166,36 +165,41 @@ class BluetoothAidlTest : public ::testing::TestWithParam { BluetoothAidlTest& parent_; public: - BluetoothHciCallbacks(BluetoothAidlTest& parent) : parent_(parent){}; + explicit BluetoothHciCallbacks(BluetoothAidlTest& parent) + : parent_(parent){}; - virtual ~BluetoothHciCallbacks() = default; + ~BluetoothHciCallbacks() override = default; - ndk::ScopedAStatus initializationComplete(Status status) { + ndk::ScopedAStatus initializationComplete(Status status) override { parent_.initialized_promise.set_value(status == Status::SUCCESS); ALOGV("%s (status = %d)", __func__, static_cast(status)); return ScopedAStatus::ok(); }; - ndk::ScopedAStatus hciEventReceived(const std::vector& event) { + ndk::ScopedAStatus hciEventReceived( + const std::vector& event) override { parent_.event_cb_count++; parent_.event_queue.push(event); ALOGV("Event received (length = %d)", static_cast(event.size())); return ScopedAStatus::ok(); }; - ndk::ScopedAStatus aclDataReceived(const std::vector& data) { + ndk::ScopedAStatus aclDataReceived( + const std::vector& data) override { parent_.acl_cb_count++; parent_.acl_queue.push(data); return ScopedAStatus::ok(); }; - ndk::ScopedAStatus scoDataReceived(const std::vector& data) { + ndk::ScopedAStatus scoDataReceived( + const std::vector& data) override { parent_.sco_cb_count++; parent_.sco_queue.push(data); return ScopedAStatus::ok(); }; - ndk::ScopedAStatus isoDataReceived(const std::vector& data) { + ndk::ScopedAStatus isoDataReceived( + const std::vector& data) override { parent_.iso_cb_count++; parent_.iso_queue.push(data); return ScopedAStatus::ok(); @@ -205,7 +209,8 @@ class BluetoothAidlTest : public ::testing::TestWithParam { template class WaitQueue { public: - WaitQueue(){}; + WaitQueue() = default; + ; virtual ~WaitQueue() = default; @@ -289,22 +294,22 @@ class BluetoothAidlTest : public ::testing::TestWithParam { std::shared_ptr hci; std::shared_ptr hci_cb; - AIBinder_DeathRecipient* bluetooth_hci_death_recipient; + AIBinder_DeathRecipient* bluetooth_hci_death_recipient{}; WaitQueue> event_queue; WaitQueue> acl_queue; WaitQueue> sco_queue; WaitQueue> iso_queue; std::promise initialized_promise; - int event_cb_count; - int sco_cb_count; - int acl_cb_count; - int iso_cb_count; + int event_cb_count{}; + int sco_cb_count{}; + int acl_cb_count{}; + int iso_cb_count{}; - int max_acl_data_packet_length; - int max_sco_data_packet_length; - int max_acl_data_packets; - int max_sco_data_packets; + int max_acl_data_packet_length{}; + int max_sco_data_packet_length{}; + int max_acl_data_packets{}; + int max_sco_data_packets{}; std::vector sco_connection_handles; std::vector acl_connection_handles; @@ -431,13 +436,13 @@ void BluetoothAidlTest::setSynchronousFlowControlEnable() { // Send an HCI command (in Loopback mode) and check the response. void BluetoothAidlTest::sendAndCheckHci(int num_packets) { - ThroughputLogger logger = {__func__}; - int command_size = 0; + ThroughputLogger logger{__func__}; + size_t command_size = 0; char new_name[] = "John Jacob Jingleheimer Schmidt ___________________"; size_t new_name_length = strlen(new_name); for (int n = 0; n < num_packets; n++) { // The name to set is new_name - std::array name_array; + std::array name_array{}; for (size_t i = 0; i < new_name_length; i++) { name_array[i] = new_name[i]; } @@ -476,7 +481,7 @@ void BluetoothAidlTest::sendAndCheckHci(int num_packets) { // Send a SCO data packet (in Loopback mode) and check the response. void BluetoothAidlTest::sendAndCheckSco(int num_packets, size_t size, uint16_t handle) { - ThroughputLogger logger = {__func__}; + ThroughputLogger logger{__func__}; for (int n = 0; n < num_packets; n++) { // Send a SCO packet std::vector sco_packet; @@ -503,7 +508,7 @@ void BluetoothAidlTest::sendAndCheckSco(int num_packets, size_t size, // Send an ACL data packet (in Loopback mode) and check the response. void BluetoothAidlTest::sendAndCheckAcl(int num_packets, size_t size, uint16_t handle) { - ThroughputLogger logger = {__func__}; + ThroughputLogger logger{__func__}; for (int n = 0; n < num_packets; n++) { // Send an ACL packet with counting data auto payload = std::make_unique<::bluetooth::packet::RawBuilder>(); @@ -551,7 +556,7 @@ int BluetoothAidlTest::wait_for_completed_packets_event(uint16_t handle) { return packets_processed; } auto completed_packets = event_view.GetCompletedPackets(); - for (const auto entry : completed_packets) { + for (const auto& entry : completed_packets) { EXPECT_EQ(handle, entry.connection_handle_); packets_processed += entry.host_num_of_completed_packets_; } @@ -820,28 +825,32 @@ TEST_P(BluetoothAidlTest, CallInitializeTwice) { class SecondCb : public aidl::android::hardware::bluetooth::BnBluetoothHciCallbacks { public: - ndk::ScopedAStatus initializationComplete(Status status) { + ndk::ScopedAStatus initializationComplete(Status status) override { EXPECT_EQ(status, Status::ALREADY_INITIALIZED); init_promise.set_value(); return ScopedAStatus::ok(); }; - ndk::ScopedAStatus hciEventReceived(const std::vector& /*event*/) { + ndk::ScopedAStatus hciEventReceived( + const std::vector& /*event*/) override { ADD_FAILURE(); return ScopedAStatus::ok(); }; - ndk::ScopedAStatus aclDataReceived(const std::vector& /*data*/) { + ndk::ScopedAStatus aclDataReceived( + const std::vector& /*data*/) override { ADD_FAILURE(); return ScopedAStatus::ok(); }; - ndk::ScopedAStatus scoDataReceived(const std::vector& /*data*/) { + ndk::ScopedAStatus scoDataReceived( + const std::vector& /*data*/) override { ADD_FAILURE(); return ScopedAStatus::ok(); }; - ndk::ScopedAStatus isoDataReceived(const std::vector& /*data*/) { + ndk::ScopedAStatus isoDataReceived( + const std::vector& /*data*/) override { ADD_FAILURE(); return ScopedAStatus::ok(); };