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

Commit 44da55c0 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

bta/test: Add controller mocks

Will be needed by leaudio unit test.

Bug: 150670922
Tag: #feature
Sponsor: jpawlowski@
Test: NA

Change-Id: I77b854c0aa83d9e416983af0c91c5e9ffa7d9954
parent a7165129
Loading
Loading
Loading
Loading
+74 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 HIMSA II K/S - www.himsa.dk.
 * Represented by EHIMA - www.ehima.com
 *
 * 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 "mock_controller.h"

#include "device/include/controller.h"

static controller::MockControllerInterface* controller_interface = nullptr;

void controller::SetMockControllerInterface(
    MockControllerInterface* interface) {
  controller_interface = interface;
}

uint16_t get_iso_data_size(void) {
  LOG_ASSERT(controller_interface) << "Mock controller not set!";
  return controller_interface->GetIsoDataSize();
}

uint8_t get_iso_buffer_count(void) {
  LOG_ASSERT(controller_interface) << "Mock controller not set!";
  return controller_interface->GetIsoBufferCount();
}

bool supports_ble_isochronous_broadcaster(void) {
  LOG_ASSERT(controller_interface) << "Mock controller not set!";
  return controller_interface->SupportsBleIsochronousBroadcaster();
}

bool supports_ble_2m_phy(void) {
  LOG_ASSERT(controller_interface) << "Mock controller not set!";
  return controller_interface->SupportsBle2mPhy();
}

bool supports_ble_connected_isochronous_stream_central(void) {
  LOG_ASSERT(controller_interface) << "Mock controller not set!";
  return controller_interface->SupportsBleConnectedIsochronousStreamCentral();
}

bool supports_ble_connected_isochronous_stream_peripheral(void) {
  LOG_ASSERT(controller_interface) << "Mock controller not set!";
  return controller_interface
      ->SupportsBleConnectedIsochronousStreamPeripheral();
}

const controller_t* controller_get_interface() {
  static controller_t* controller_instance = new controller_t();

  controller_instance->get_iso_data_size = &get_iso_data_size;
  controller_instance->get_iso_buffer_count = &get_iso_buffer_count;
  controller_instance->supports_ble_isochronous_broadcaster =
      &supports_ble_isochronous_broadcaster;
  controller_instance->supports_ble_2m_phy = &supports_ble_2m_phy;
  controller_instance->supports_ble_connected_isochronous_stream_central =
      &supports_ble_connected_isochronous_stream_central;
  controller_instance->supports_ble_connected_isochronous_stream_peripheral =
      &supports_ble_connected_isochronous_stream_peripheral;

  return controller_instance;
}
+51 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 HIMSA II K/S - www.himsa.dk.
 * Represented by EHIMA - www.ehima.com
 *
 * 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 <base/callback.h>
#include <gmock/gmock.h>

#include "hcimsgs.h"

namespace controller {
class ControllerInterface {
 public:
  virtual uint8_t GetIsoBufferCount(void) = 0;
  virtual uint16_t GetIsoDataSize(void) = 0;
  virtual bool SupportsBleConnectedIsochronousStreamCentral(void) = 0;
  virtual bool SupportsBleConnectedIsochronousStreamPeripheral(void) = 0;
  virtual bool SupportsBleIsochronousBroadcaster(void) = 0;
  virtual bool SupportsBle2mPhy(void) = 0;

  virtual ~ControllerInterface() = default;
};

class MockControllerInterface : public ControllerInterface {
 public:
  MOCK_METHOD((uint8_t), GetIsoBufferCount, (), (override));
  MOCK_METHOD((uint16_t), GetIsoDataSize, (), (override));
  MOCK_METHOD((bool), SupportsBleConnectedIsochronousStreamCentral, (),
              (override));
  MOCK_METHOD((bool), SupportsBleConnectedIsochronousStreamPeripheral, (),
              (override));
  MOCK_METHOD((bool), SupportsBleIsochronousBroadcaster, (), (override));
  MOCK_METHOD((bool), SupportsBle2mPhy, (), (override));
};

void SetMockControllerInterface(
    MockControllerInterface* mock_controller_interface);
}  // namespace controller