zephyr/tests/bluetooth/audio/mocks/include/bap_stream_expects.h
Emil Gydesen b857ef7f83 Bluetooth: BAP: Add ISO state callbacks
Add callbacks to the stream objects that reflects the
state of the isochronous channel. The connected callback
is called when the isochronous channel is connected, and
similarly the disconnected callback is called when it is
disconnected.

There is a special case for unicast, where if the ACL
disconnects first, then we won't get a ISO disconnect
callback. It should be assumed that the isochronous channel
is no longer valid when the BAP stream enters the idle state,
i.e. when the "released" callback is called.

The purpose of the new callbacks is to provide additional
information to the application. Especially the unicast client
can use this to determine when the stream_start function
can be called again, as there can only ever be 1 outstanding
CIS connection request at a time, but there can be multiple
GATT requests.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-01-22 12:59:11 +01:00

278 lines
9.9 KiB
C

/*
* Copyright (c) 2023 Codecoup
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef MOCKS_BAP_STREAM_EXPECTS_H_
#define MOCKS_BAP_STREAM_EXPECTS_H_
#include <zephyr/bluetooth/audio/bap.h>
#include "bap_stream.h"
#include "expects_util.h"
#define expect_bt_bap_stream_ops_configured_called_once(_stream, _pref) \
do { \
const char *func_name = "bt_bap_stream_ops.configured"; \
\
zexpect_call_count(func_name, 1, mock_bap_stream_configured_cb_fake.call_count); \
\
if (mock_bap_stream_configured_cb_fake.call_count > 0) { \
IF_NOT_EMPTY(_stream, ( \
zexpect_equal_ptr(_stream, mock_bap_stream_configured_cb_fake.arg0_val, \
"'%s()' was called with incorrect '%s' value", \
func_name, "stream");)) \
\
IF_NOT_EMPTY(_pref, ( \
/* TODO */ \
zassert_unreachable("Not implemented");)) \
} \
} while (0)
static inline void expect_bt_bap_stream_ops_configured_not_called(void)
{
const char *func_name = "bt_bap_stream_ops.configured";
zexpect_call_count(func_name, 0, mock_bap_stream_configured_cb_fake.call_count);
}
static inline void expect_bt_bap_stream_ops_qos_set_called_once(struct bt_bap_stream *stream)
{
const char *func_name = "bt_bap_stream_ops.qos_set";
zexpect_call_count(func_name, 1, mock_bap_stream_qos_set_cb_fake.call_count);
if (mock_bap_stream_qos_set_cb_fake.call_count > 0) {
zexpect_equal_ptr(stream, mock_bap_stream_qos_set_cb_fake.arg0_val,
"'%s()' was called with incorrect '%s'", func_name, "stream");
}
}
static inline void expect_bt_bap_stream_ops_qos_set_not_called(void)
{
const char *func_name = "bt_bap_stream_ops.qos_set";
zexpect_call_count(func_name, 0, mock_bap_stream_qos_set_cb_fake.call_count);
}
static inline void expect_bt_bap_stream_ops_enabled_called_once(struct bt_bap_stream *stream)
{
const char *func_name = "bt_bap_stream_ops.enabled";
zexpect_call_count(func_name, 1, mock_bap_stream_enabled_cb_fake.call_count);
if (mock_bap_stream_enabled_cb_fake.call_count > 0) {
zexpect_equal_ptr(stream, mock_bap_stream_enabled_cb_fake.arg0_val,
"'%s()' was called with incorrect '%s'", func_name, "stream");
}
}
static inline void expect_bt_bap_stream_ops_enabled_not_called(void)
{
const char *func_name = "bt_bap_stream_ops.enabled";
zexpect_call_count(func_name, 0, mock_bap_stream_enabled_cb_fake.call_count);
}
static inline void expect_bt_bap_stream_ops_metadata_updated_called_once(
struct bt_bap_stream *stream)
{
const char *func_name = "bt_bap_stream_ops.metadata_updated";
zexpect_call_count(func_name, 1, mock_bap_stream_metadata_updated_cb_fake.call_count);
if (mock_bap_stream_metadata_updated_cb_fake.call_count > 0) {
zexpect_equal_ptr(stream, mock_bap_stream_metadata_updated_cb_fake.arg0_val,
"'%s()' was called with incorrect '%s'", func_name, "stream");
}
}
static inline void expect_bt_bap_stream_ops_metadata_updated_not_called(void)
{
const char *func_name = "bt_bap_stream_ops.metadata_updated";
zexpect_call_count(func_name, 0, mock_bap_stream_metadata_updated_cb_fake.call_count);
}
static inline void expect_bt_bap_stream_ops_disabled_called_once(struct bt_bap_stream *stream)
{
const char *func_name = "bt_bap_stream_ops.disabled";
zexpect_call_count(func_name, 1, mock_bap_stream_disabled_cb_fake.call_count);
if (mock_bap_stream_disabled_cb_fake.call_count > 0) {
zexpect_equal_ptr(stream, mock_bap_stream_disabled_cb_fake.arg0_val,
"'%s()' was called with incorrect '%s'", func_name, "stream");
}
}
static inline void expect_bt_bap_stream_ops_disabled_not_called(void)
{
const char *func_name = "bt_bap_stream_ops.disabled";
zexpect_call_count(func_name, 0, mock_bap_stream_disabled_cb_fake.call_count);
}
static inline void expect_bt_bap_stream_ops_released_called(const struct bt_bap_stream *streams[],
unsigned int count)
{
const char *func_name = "bt_bap_stream_ops.released";
zexpect_call_count(func_name, count, mock_bap_stream_released_cb_fake.call_count);
for (unsigned int i = 0; i < count; i++) {
bool found = false;
for (unsigned int j = 0; j < mock_bap_stream_released_cb_fake.call_count; j++) {
found = streams[i] == mock_bap_stream_released_cb_fake.arg0_history[j];
if (found) {
break;
}
}
zexpect_true(found, "'%s()' not called with %p stream", func_name, streams[i]);
}
}
static inline void expect_bt_bap_stream_ops_released_called_once(const struct bt_bap_stream *stream)
{
expect_bt_bap_stream_ops_released_called(&stream, 1);
}
static inline void expect_bt_bap_stream_ops_released_not_called(void)
{
const char *func_name = "bt_bap_stream_ops.released";
zexpect_equal(0, mock_bap_stream_released_cb_fake.call_count,
"'%s()' was called unexpectedly", func_name);
}
static inline void expect_bt_bap_stream_ops_started_called_once(struct bt_bap_stream *stream)
{
const char *func_name = "bt_bap_stream_ops.started";
zexpect_call_count(func_name, 1, mock_bap_stream_started_cb_fake.call_count);
if (mock_bap_stream_started_cb_fake.call_count > 0) {
zexpect_equal_ptr(stream, mock_bap_stream_started_cb_fake.arg0_val,
"'%s()' was called with incorrect '%s'", func_name, "stream");
}
}
static inline void expect_bt_bap_stream_ops_started_not_called(void)
{
const char *func_name = "bt_bap_stream_ops.started";
zexpect_call_count(func_name, 0, mock_bap_stream_started_cb_fake.call_count);
}
#define expect_bt_bap_stream_ops_stopped_called_once(_stream, _reason) \
do { \
const char *func_name = "bt_bap_stream_ops.stopped"; \
\
zexpect_call_count(func_name, 1, mock_bap_stream_stopped_cb_fake.call_count); \
\
if (mock_bap_stream_stopped_cb_fake.call_count > 0) { \
IF_NOT_EMPTY(_stream, ( \
zexpect_equal_ptr(_stream, mock_bap_stream_stopped_cb_fake.arg0_val, \
"'%s()' was called with incorrect '%s' value", \
func_name, "stream");)) \
\
IF_NOT_EMPTY(_reason, ( \
zexpect_equal(_reason, mock_bap_stream_stopped_cb_fake.arg1_val, \
"'%s()' was called with incorrect '%s' value", \
func_name, "reason");)) \
} \
} while (0)
static inline void expect_bt_bap_stream_ops_stopped_not_called(void)
{
const char *func_name = "bt_bap_stream_ops.stopped";
zexpect_call_count(func_name, 0, mock_bap_stream_stopped_cb_fake.call_count);
}
static inline void
expect_bt_bap_stream_ops_connected_called_once(const struct bt_bap_stream *stream)
{
const char *func_name = "bt_bap_stream_ops.connected";
zexpect_call_count(func_name, 1, mock_bap_stream_connected_cb_fake.call_count);
if (mock_bap_stream_connected_cb_fake.call_count > 0) {
zexpect_equal_ptr(stream, mock_bap_stream_connected_cb_fake.arg0_val,
"'%s()' was called with incorrect '%s'", func_name, "stream");
}
}
static inline void
expect_bt_bap_stream_ops_connected_called_twice(const struct bt_bap_stream *stream)
{
const char *func_name = "bt_bap_stream_ops.connected";
zexpect_call_count(func_name, 2, mock_bap_stream_connected_cb_fake.call_count);
if (mock_bap_stream_connected_cb_fake.call_count > 0) {
zexpect_equal_ptr(stream, mock_bap_stream_connected_cb_fake.arg0_val,
"'%s()' was called with incorrect '%s'", func_name, "stream");
}
}
static inline void
expect_bt_bap_stream_ops_disconnected_called_once(const struct bt_bap_stream *stream)
{
const char *func_name = "bt_bap_stream_ops.disconnected";
zexpect_call_count(func_name, 1, mock_bap_stream_disconnected_cb_fake.call_count);
if (mock_bap_stream_disconnected_cb_fake.call_count > 0) {
zexpect_equal_ptr(stream, mock_bap_stream_disconnected_cb_fake.arg0_val,
"'%s()' was called with incorrect '%s'", func_name, "stream");
}
}
static inline void expect_bt_bap_stream_ops_recv_called_once(struct bt_bap_stream *stream,
const struct bt_iso_recv_info *info,
struct net_buf *buf)
{
const char *func_name = "bt_bap_stream_ops.recv";
zexpect_call_count(func_name, 1, mock_bap_stream_recv_cb_fake.call_count);
if (mock_bap_stream_recv_cb_fake.call_count > 0) {
zexpect_equal_ptr(stream, mock_bap_stream_recv_cb_fake.arg0_val,
"'%s()' was called with incorrect '%s'", func_name, "stream");
}
/* TODO: validate info && buf */
}
static inline void expect_bt_bap_stream_ops_recv_not_called(void)
{
const char *func_name = "bt_bap_stream_ops.recv";
zexpect_call_count(func_name, 0, mock_bap_stream_recv_cb_fake.call_count);
}
static inline void expect_bt_bap_stream_ops_sent_called_once(struct bt_bap_stream *stream)
{
const char *func_name = "bt_bap_stream_ops.sent";
zexpect_call_count(func_name, 1, mock_bap_stream_sent_cb_fake.call_count);
if (mock_bap_stream_sent_cb_fake.call_count > 0) {
zexpect_equal_ptr(stream, mock_bap_stream_sent_cb_fake.arg0_val,
"'%s()' was called with incorrect '%s'", func_name, "stream");
}
}
static inline void expect_bt_bap_stream_ops_sent_not_called(void)
{
const char *func_name = "bt_bap_stream_ops.sent";
zexpect_call_count(func_name, 0, mock_bap_stream_sent_cb_fake.call_count);
}
#endif /* MOCKS_BAP_STREAM_EXPECTS_H_ */