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

Commit aafbd6fb authored by Chris Manton's avatar Chris Manton Committed by Automerger Merge Worker
Browse files

mocks: Introduce mock_btif_sock_rfc am: 0e31b6b3 am: 5bc1755b am: 103db81b

parents 78146b97 103db81b
Loading
Loading
Loading
Loading
+125 −0
Original line number Original line 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.
 */
/*
 * Generated mock file from original source file
 *   Functions generated:10
 *
 *  mockcify.pl ver 0.6.2
 */

#include <cstdint>

// Mock include file to share data between tests and mock
#include "test/common/mock_functions.h"
#include "test/mock/mock_btif_sock_rfc.h"

// Original usings
using bluetooth::Uuid;

// Mocked internal structures, if any

namespace test {
namespace mock {
namespace btif_sock_rfc {

// Function state capture and return values, if needed
struct bta_co_rfc_data_incoming bta_co_rfc_data_incoming;
struct bta_co_rfc_data_outgoing bta_co_rfc_data_outgoing;
struct bta_co_rfc_data_outgoing_size bta_co_rfc_data_outgoing_size;
struct btsock_rfc_cleanup btsock_rfc_cleanup;
struct btsock_rfc_connect btsock_rfc_connect;
struct btsock_rfc_control_req btsock_rfc_control_req;
struct btsock_rfc_disconnect btsock_rfc_disconnect;
struct btsock_rfc_init btsock_rfc_init;
struct btsock_rfc_listen btsock_rfc_listen;
struct btsock_rfc_signaled btsock_rfc_signaled;

}  // namespace btif_sock_rfc
}  // namespace mock
}  // namespace test

// Mocked function return values, if any
namespace test {
namespace mock {
namespace btif_sock_rfc {

int bta_co_rfc_data_incoming::return_value = 0;
int bta_co_rfc_data_outgoing::return_value = 0;
int bta_co_rfc_data_outgoing_size::return_value = 0;
bt_status_t btsock_rfc_connect::return_value = BT_STATUS_SUCCESS;
bt_status_t btsock_rfc_control_req::return_value = BT_STATUS_SUCCESS;
bt_status_t btsock_rfc_disconnect::return_value = BT_STATUS_SUCCESS;
bt_status_t btsock_rfc_init::return_value = BT_STATUS_SUCCESS;
bt_status_t btsock_rfc_listen::return_value = BT_STATUS_SUCCESS;

}  // namespace btif_sock_rfc
}  // namespace mock
}  // namespace test

// Mocked functions, if any
int bta_co_rfc_data_incoming(uint32_t id, BT_HDR* p_buf) {
  inc_func_call_count(__func__);
  return test::mock::btif_sock_rfc::bta_co_rfc_data_incoming(id, p_buf);
}
int bta_co_rfc_data_outgoing(uint32_t id, uint8_t* buf, uint16_t size) {
  inc_func_call_count(__func__);
  return test::mock::btif_sock_rfc::bta_co_rfc_data_outgoing(id, buf, size);
}
int bta_co_rfc_data_outgoing_size(uint32_t id, int* size) {
  inc_func_call_count(__func__);
  return test::mock::btif_sock_rfc::bta_co_rfc_data_outgoing_size(id, size);
}
void btsock_rfc_cleanup(void) {
  inc_func_call_count(__func__);
  test::mock::btif_sock_rfc::btsock_rfc_cleanup();
}
bt_status_t btsock_rfc_connect(const RawAddress* bd_addr,
                               const Uuid* service_uuid, int channel,
                               int* sock_fd, int flags, int app_uid) {
  inc_func_call_count(__func__);
  return test::mock::btif_sock_rfc::btsock_rfc_connect(
      bd_addr, service_uuid, channel, sock_fd, flags, app_uid);
}
bt_status_t btsock_rfc_control_req(uint8_t dlci, const RawAddress& bd_addr,
                                   uint8_t modem_signal, uint8_t break_signal,
                                   uint8_t discard_buffers,
                                   uint8_t break_signal_seq, bool fc) {
  inc_func_call_count(__func__);
  return test::mock::btif_sock_rfc::btsock_rfc_control_req(
      dlci, bd_addr, modem_signal, break_signal, discard_buffers,
      break_signal_seq, fc);
}
bt_status_t btsock_rfc_disconnect(const RawAddress* bd_addr) {
  inc_func_call_count(__func__);
  return test::mock::btif_sock_rfc::btsock_rfc_disconnect(bd_addr);
}
bt_status_t btsock_rfc_init(int poll_thread_handle, uid_set_t* set) {
  inc_func_call_count(__func__);
  return test::mock::btif_sock_rfc::btsock_rfc_init(poll_thread_handle, set);
}
bt_status_t btsock_rfc_listen(const char* service_name,
                              const Uuid* service_uuid, int channel,
                              int* sock_fd, int flags, int app_uid) {
  inc_func_call_count(__func__);
  return test::mock::btif_sock_rfc::btsock_rfc_listen(
      service_name, service_uuid, channel, sock_fd, flags, app_uid);
}
void btsock_rfc_signaled(int fd, int flags, uint32_t id) {
  inc_func_call_count(__func__);
  test::mock::btif_sock_rfc::btsock_rfc_signaled(fd, flags, id);
}
// Mocked functions complete
// END mockcify generation
+184 −0
Original line number Original line 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.
 */
#pragma once

/*
 * Generated mock file from original source file
 *   Functions generated:10
 *
 *  mockcify.pl ver 0.6.2
 */

#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>

#include <cstdint>
#include <functional>

#include "btif/include/btif_uid.h"
#include "stack/include/bt_hdr.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"

// Original usings
using bluetooth::Uuid;

// Mocked compile conditionals, if any

namespace test {
namespace mock {
namespace btif_sock_rfc {

// Shared state between mocked functions and tests
// Name: bta_co_rfc_data_incoming
// Params: uint32_t id, BT_HDR* p_buf
// Return: int
struct bta_co_rfc_data_incoming {
  static int return_value;
  std::function<int(uint32_t id, BT_HDR* p_buf)> body{
      [](uint32_t id, BT_HDR* p_buf) { return return_value; }};
  int operator()(uint32_t id, BT_HDR* p_buf) { return body(id, p_buf); };
};
extern struct bta_co_rfc_data_incoming bta_co_rfc_data_incoming;

// Name: bta_co_rfc_data_outgoing
// Params: uint32_t id, uint8_t* buf, uint16_t size
// Return: int
struct bta_co_rfc_data_outgoing {
  static int return_value;
  std::function<int(uint32_t id, uint8_t* buf, uint16_t size)> body{
      [](uint32_t id, uint8_t* buf, uint16_t size) { return return_value; }};
  int operator()(uint32_t id, uint8_t* buf, uint16_t size) {
    return body(id, buf, size);
  };
};
extern struct bta_co_rfc_data_outgoing bta_co_rfc_data_outgoing;

// Name: bta_co_rfc_data_outgoing_size
// Params: uint32_t id, int* size
// Return: int
struct bta_co_rfc_data_outgoing_size {
  static int return_value;
  std::function<int(uint32_t id, int* size)> body{
      [](uint32_t id, int* size) { return return_value; }};
  int operator()(uint32_t id, int* size) { return body(id, size); };
};
extern struct bta_co_rfc_data_outgoing_size bta_co_rfc_data_outgoing_size;

// Name: btsock_rfc_cleanup
// Params: void
// Return: void
struct btsock_rfc_cleanup {
  std::function<void(void)> body{[](void) {}};
  void operator()(void) { body(); };
};
extern struct btsock_rfc_cleanup btsock_rfc_cleanup;

// Name: btsock_rfc_connect
// Params: const RawAddress* bd_addr, const Uuid* service_uuid, int channel,
// int* sock_fd, int flags, int app_uid Return: bt_status_t
struct btsock_rfc_connect {
  static bt_status_t return_value;
  std::function<bt_status_t(const RawAddress* bd_addr, const Uuid* service_uuid,
                            int channel, int* sock_fd, int flags, int app_uid)>
      body{[](const RawAddress* bd_addr, const Uuid* service_uuid, int channel,
              int* sock_fd, int flags, int app_uid) { return return_value; }};
  bt_status_t operator()(const RawAddress* bd_addr, const Uuid* service_uuid,
                         int channel, int* sock_fd, int flags, int app_uid) {
    return body(bd_addr, service_uuid, channel, sock_fd, flags, app_uid);
  };
};
extern struct btsock_rfc_connect btsock_rfc_connect;

// Name: btsock_rfc_control_req
// Params: uint8_t dlci, const RawAddress& bd_addr, uint8_t modem_signal,
// uint8_t break_signal, uint8_t discard_buffers, uint8_t break_signal_seq, bool
// fc Return: bt_status_t
struct btsock_rfc_control_req {
  static bt_status_t return_value;
  std::function<bt_status_t(uint8_t dlci, const RawAddress& bd_addr,
                            uint8_t modem_signal, uint8_t break_signal,
                            uint8_t discard_buffers, uint8_t break_signal_seq,
                            bool fc)>
      body{[](uint8_t dlci, const RawAddress& bd_addr, uint8_t modem_signal,
              uint8_t break_signal, uint8_t discard_buffers,
              uint8_t break_signal_seq, bool fc) { return return_value; }};
  bt_status_t operator()(uint8_t dlci, const RawAddress& bd_addr,
                         uint8_t modem_signal, uint8_t break_signal,
                         uint8_t discard_buffers, uint8_t break_signal_seq,
                         bool fc) {
    return body(dlci, bd_addr, modem_signal, break_signal, discard_buffers,
                break_signal_seq, fc);
  };
};
extern struct btsock_rfc_control_req btsock_rfc_control_req;

// Name: btsock_rfc_disconnect
// Params: const RawAddress* bd_addr
// Return: bt_status_t
struct btsock_rfc_disconnect {
  static bt_status_t return_value;
  std::function<bt_status_t(const RawAddress* bd_addr)> body{
      [](const RawAddress* bd_addr) { return return_value; }};
  bt_status_t operator()(const RawAddress* bd_addr) { return body(bd_addr); };
};
extern struct btsock_rfc_disconnect btsock_rfc_disconnect;

// Name: btsock_rfc_init
// Params: int poll_thread_handle, uid_set_t* set
// Return: bt_status_t
struct btsock_rfc_init {
  static bt_status_t return_value;
  std::function<bt_status_t(int poll_thread_handle, uid_set_t* set)> body{
      [](int poll_thread_handle, uid_set_t* set) { return return_value; }};
  bt_status_t operator()(int poll_thread_handle, uid_set_t* set) {
    return body(poll_thread_handle, set);
  };
};
extern struct btsock_rfc_init btsock_rfc_init;

// Name: btsock_rfc_listen
// Params: const char* service_name, const Uuid* service_uuid, int channel, int*
// sock_fd, int flags, int app_uid Return: bt_status_t
struct btsock_rfc_listen {
  static bt_status_t return_value;
  std::function<bt_status_t(const char* service_name, const Uuid* service_uuid,
                            int channel, int* sock_fd, int flags, int app_uid)>
      body{[](const char* service_name, const Uuid* service_uuid, int channel,
              int* sock_fd, int flags, int app_uid) { return return_value; }};
  bt_status_t operator()(const char* service_name, const Uuid* service_uuid,
                         int channel, int* sock_fd, int flags, int app_uid) {
    return body(service_name, service_uuid, channel, sock_fd, flags, app_uid);
  };
};
extern struct btsock_rfc_listen btsock_rfc_listen;

// Name: btsock_rfc_signaled
// Params:  int fd, int flags, uint32_t id
// Return: void
struct btsock_rfc_signaled {
  std::function<void(int fd, int flags, uint32_t id)> body{
      [](int fd, int flags, uint32_t id) {}};
  void operator()(int fd, int flags, uint32_t id) { body(fd, flags, id); };
};
extern struct btsock_rfc_signaled btsock_rfc_signaled;

}  // namespace btif_sock_rfc
}  // namespace mock
}  // namespace test

// END mockcify generation
 No newline at end of file
+27 −0
Original line number Original line Diff line number Diff line


*** mock-C-ify

Any legacy code that is incapable of mocking may be a candidate for the
use of the mockCify tool to mock code in order to provide symbolic endpoints during the linkage
phase with additonal run time configurability to provide crafted testing solution.


** To use

<mockcify_tool> <namespace> < <source_code>

mockcify_tool: mockcify.pl
namespace: A brief single token namespace conventionally used from the path and filename
source_code: The C code being mocked.

```
e.g.
mockcify.pl btif_sock_rfc < btif/src/btif_sock_rfc.cc
```

NOTE: This tool is does not handle Cpp code well and is recommended to use gmock for those solutions.

Other Cpp language syntax, such as move semantics and lambdas also do not parse well and may need hand
crafting for those last few pieces.