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

Commit 1de30943 authored by Jack He's avatar Jack He
Browse files

L2CAP: Add mocks for fixed channel manager and classic module

* Add mocks for l2cap::classic::FixedChannelManager
  and l2cap::classic::L2capClassicModule

Bug: 138261142
Test: make with a no-op test and run it
Change-Id: I82cd5b4caa6474b154bf9d4736e32c980fb9aba3
parent df79a055
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -31,6 +31,10 @@ namespace classic {

class L2capClassicModule;

namespace testing {
class MockFixedChannelManager;
}

namespace internal {
class LinkManager;
class FixedChannelServiceManagerImpl;
@@ -102,7 +106,7 @@ class FixedChannelManager {
   *
   * Returns: true if connection was able to be initiated, false otherwise.
   */
  bool ConnectServices(hci::Address device, OnConnectionFailureCallback on_fail_callback, os::Handler* handler);
  virtual bool ConnectServices(hci::Address device, OnConnectionFailureCallback on_fail_callback, os::Handler* handler);

  /**
   * Register a service to receive incoming connections bound to a specific channel.
@@ -124,11 +128,14 @@ class FixedChannelManager {
   * @param on_open_callback: A callback to indicate success of a connection initiated from a remote device.
   * @param handler: The handler context in which to execute the @callback parameter.
   */
  bool RegisterService(Cid cid, const SecurityPolicy& security_policy,
  virtual bool RegisterService(Cid cid, const SecurityPolicy& security_policy,
                               OnRegistrationCompleteCallback on_registration_complete,
                               OnConnectionOpenCallback on_connection_open, os::Handler* handler);

  virtual ~FixedChannelManager() = default;

  friend class L2capClassicModule;
  friend class testing::MockFixedChannelManager;

 private:
  // The constructor is not to be used by user code
+42 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 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.
 */
#pragma once

#include "l2cap/classic/fixed_channel_manager.h"

#include <gmock/gmock.h>

// Unit test interfaces
namespace bluetooth {
namespace l2cap {
namespace classic {
namespace testing {

class MockFixedChannelManager : public FixedChannelManager {
 public:
  MockFixedChannelManager() : FixedChannelManager(nullptr, nullptr, nullptr){};
  MOCK_METHOD(bool, ConnectServices,
              (hci::Address device, OnConnectionFailureCallback on_fail_callback, os::Handler* handler), (override));
  MOCK_METHOD(bool, RegisterService,
              (Cid cid, const SecurityPolicy& security_policy, OnRegistrationCompleteCallback on_registration_complete,
               OnConnectionOpenCallback on_connection_open, os::Handler* handler),
              (override));
};

}  // namespace testing
}  // namespace classic
}  // namespace l2cap
}  // namespace bluetooth
+5 −1
Original line number Diff line number Diff line
@@ -50,6 +50,10 @@ struct L2capClassicModule::impl {
                                      &dynamic_channel_service_manager_impl_, &parameter_provider_};
};

L2capClassicModule::L2capClassicModule() {}

L2capClassicModule::~L2capClassicModule() {}

void L2capClassicModule::ListDependencies(ModuleList* list) {
  list->add<hci::AclManager>();
}
+5 −5
Original line number Diff line number Diff line
@@ -27,18 +27,18 @@ namespace classic {

class L2capClassicModule : public bluetooth::Module {
 public:
  L2capClassicModule() = default;
  ~L2capClassicModule() = default;
  L2capClassicModule();
  virtual ~L2capClassicModule();

  /**
   * Get the api to the classic fixed channel l2cap module
   */
  std::unique_ptr<FixedChannelManager> GetFixedChannelManager();
  virtual std::unique_ptr<FixedChannelManager> GetFixedChannelManager();

  /**
   * Get the api to the classic dynamic channel l2cap module
   */
  std::unique_ptr<DynamicChannelManager> GetDynamicChannelManager();
  virtual std::unique_ptr<DynamicChannelManager> GetDynamicChannelManager();

  static const ModuleFactory Factory;

+37 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 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.
 */
#pragma once

#include "l2cap/classic/l2cap_classic_module.h"

#include <gmock/gmock.h>

// Unit test interfaces
namespace bluetooth {
namespace l2cap {
namespace classic {
namespace testing {

class MockL2capClassicModule : public L2capClassicModule {
 public:
  MOCK_METHOD(std::unique_ptr<FixedChannelManager>, GetFixedChannelManager, (), (override));
  MOCK_METHOD(std::unique_ptr<DynamicChannelManager>, GetDynamicChannelManager, (), (override));
};

}  // namespace testing
}  // namespace classic
}  // namespace l2cap
}  // namespace bluetooth