1 /* test_common.c - common procedures for unit test of CAP initiator */
2 
3 /*
4  * Copyright (c) 2024 Nordic Semiconductor ASA
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #include <zephyr/bluetooth/audio/bap.h>
10 #include <zephyr/bluetooth/audio/bap_lc3_preset.h>
11 #include <zephyr/bluetooth/audio/cap.h>
12 #include <zephyr/bluetooth/conn.h>
13 #include <zephyr/bluetooth/hci_types.h>
14 
15 #include "bap_endpoint.h"
16 #include "cap_initiator.h"
17 #include "conn.h"
18 #include "test_common.h"
19 #include "ztest_assert.h"
20 
21 DEFINE_FFF_GLOBALS;
22 
test_mocks_init(void)23 void test_mocks_init(void)
24 {
25 	mock_cap_initiator_init();
26 }
27 
test_mocks_cleanup(void)28 void test_mocks_cleanup(void)
29 {
30 	mock_cap_initiator_cleanup();
31 }
32 
test_conn_init(struct bt_conn * conn)33 void test_conn_init(struct bt_conn *conn)
34 {
35 	conn->index = 0;
36 	conn->info.type = BT_CONN_TYPE_LE;
37 	conn->info.role = BT_CONN_ROLE_CENTRAL;
38 	conn->info.state = BT_CONN_STATE_CONNECTED;
39 	conn->info.security.level = BT_SECURITY_L2;
40 	conn->info.security.enc_key_size = BT_ENC_KEY_SIZE_MAX;
41 	conn->info.security.flags = BT_SECURITY_FLAG_OOB | BT_SECURITY_FLAG_SC;
42 }
43 
test_unicast_set_state(struct bt_cap_stream * cap_stream,struct bt_conn * conn,struct bt_bap_ep * ep,struct bt_bap_lc3_preset * preset,enum bt_bap_ep_state state)44 void test_unicast_set_state(struct bt_cap_stream *cap_stream, struct bt_conn *conn,
45 			    struct bt_bap_ep *ep, struct bt_bap_lc3_preset *preset,
46 			    enum bt_bap_ep_state state)
47 {
48 	struct bt_bap_stream *bap_stream = &cap_stream->bap_stream;
49 
50 	printk("Setting stream %p to state %d\n", bap_stream, state);
51 
52 	if (state == BT_BAP_EP_STATE_IDLE) {
53 		return;
54 	}
55 
56 	zassert_not_null(cap_stream);
57 	zassert_not_null(conn);
58 	zassert_not_null(ep);
59 	zassert_not_null(preset);
60 
61 	bap_stream->conn = conn;
62 	bap_stream->ep = ep;
63 	bap_stream->qos = &preset->qos;
64 	bap_stream->codec_cfg = &preset->codec_cfg;
65 	bap_stream->ep->status.state = state;
66 }
67