1 /*
2  * Copyright (c) 2023 Codecoup
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef MOCKS_BAP_STREAM_EXPECTS_H_
8 #define MOCKS_BAP_STREAM_EXPECTS_H_
9 
10 #include <zephyr/bluetooth/audio/bap.h>
11 
12 #include "bap_stream.h"
13 #include "expects_util.h"
14 
15 #define expect_bt_bap_stream_ops_configured_called_once(_stream, _pref)                            \
16 do {                                                                                               \
17 	const char *func_name = "bt_bap_stream_ops.configured";                                    \
18 												   \
19 	zexpect_call_count(func_name, 1, mock_bap_stream_configured_cb_fake.call_count);           \
20 												   \
21 	if (mock_bap_stream_configured_cb_fake.call_count > 0) {                                   \
22 		IF_NOT_EMPTY(_stream, (                                                            \
23 			zexpect_equal_ptr(_stream, mock_bap_stream_configured_cb_fake.arg0_val,    \
24 					  "'%s()' was called with incorrect '%s' value",           \
25 					  func_name, "stream");))                                  \
26 												   \
27 		IF_NOT_EMPTY(_pref, (                                                              \
28 			/* TODO */                                                                 \
29 			zassert_unreachable("Not implemented");))                                  \
30 	}                                                                                          \
31 } while (0)
32 
expect_bt_bap_stream_ops_configured_not_called(void)33 static inline void expect_bt_bap_stream_ops_configured_not_called(void)
34 {
35 	const char *func_name = "bt_bap_stream_ops.configured";
36 
37 	zexpect_call_count(func_name, 0, mock_bap_stream_configured_cb_fake.call_count);
38 }
39 
expect_bt_bap_stream_ops_qos_set_called_once(struct bt_bap_stream * stream)40 static inline void expect_bt_bap_stream_ops_qos_set_called_once(struct bt_bap_stream *stream)
41 {
42 	const char *func_name = "bt_bap_stream_ops.qos_set";
43 
44 	zexpect_call_count(func_name, 1, mock_bap_stream_qos_set_cb_fake.call_count);
45 
46 	if (mock_bap_stream_qos_set_cb_fake.call_count > 0) {
47 		zexpect_equal_ptr(stream, mock_bap_stream_qos_set_cb_fake.arg0_val,
48 				  "'%s()' was called with incorrect '%s'", func_name, "stream");
49 	}
50 }
51 
expect_bt_bap_stream_ops_qos_set_not_called(void)52 static inline void expect_bt_bap_stream_ops_qos_set_not_called(void)
53 {
54 	const char *func_name = "bt_bap_stream_ops.qos_set";
55 
56 	zexpect_call_count(func_name, 0, mock_bap_stream_qos_set_cb_fake.call_count);
57 }
58 
expect_bt_bap_stream_ops_enabled_called_once(struct bt_bap_stream * stream)59 static inline void expect_bt_bap_stream_ops_enabled_called_once(struct bt_bap_stream *stream)
60 {
61 	const char *func_name = "bt_bap_stream_ops.enabled";
62 
63 	zexpect_call_count(func_name, 1, mock_bap_stream_enabled_cb_fake.call_count);
64 
65 	if (mock_bap_stream_enabled_cb_fake.call_count > 0) {
66 		zexpect_equal_ptr(stream, mock_bap_stream_enabled_cb_fake.arg0_val,
67 				  "'%s()' was called with incorrect '%s'", func_name, "stream");
68 	}
69 }
70 
expect_bt_bap_stream_ops_enabled_not_called(void)71 static inline void expect_bt_bap_stream_ops_enabled_not_called(void)
72 {
73 	const char *func_name = "bt_bap_stream_ops.enabled";
74 
75 	zexpect_call_count(func_name, 0, mock_bap_stream_enabled_cb_fake.call_count);
76 }
77 
expect_bt_bap_stream_ops_metadata_updated_called_once(struct bt_bap_stream * stream)78 static inline void expect_bt_bap_stream_ops_metadata_updated_called_once(
79 								struct bt_bap_stream *stream)
80 {
81 	const char *func_name = "bt_bap_stream_ops.metadata_updated";
82 
83 	zexpect_call_count(func_name, 1, mock_bap_stream_metadata_updated_cb_fake.call_count);
84 
85 	if (mock_bap_stream_metadata_updated_cb_fake.call_count > 0) {
86 		zexpect_equal_ptr(stream, mock_bap_stream_metadata_updated_cb_fake.arg0_val,
87 				  "'%s()' was called with incorrect '%s'", func_name, "stream");
88 	}
89 }
90 
expect_bt_bap_stream_ops_metadata_updated_not_called(void)91 static inline void expect_bt_bap_stream_ops_metadata_updated_not_called(void)
92 {
93 	const char *func_name = "bt_bap_stream_ops.metadata_updated";
94 
95 	zexpect_call_count(func_name, 0, mock_bap_stream_metadata_updated_cb_fake.call_count);
96 }
97 
expect_bt_bap_stream_ops_disabled_called_once(struct bt_bap_stream * stream)98 static inline void expect_bt_bap_stream_ops_disabled_called_once(struct bt_bap_stream *stream)
99 {
100 	const char *func_name = "bt_bap_stream_ops.disabled";
101 
102 	zexpect_call_count(func_name, 1, mock_bap_stream_disabled_cb_fake.call_count);
103 
104 	if (mock_bap_stream_disabled_cb_fake.call_count > 0) {
105 		zexpect_equal_ptr(stream, mock_bap_stream_disabled_cb_fake.arg0_val,
106 				  "'%s()' was called with incorrect '%s'", func_name, "stream");
107 	}
108 }
109 
expect_bt_bap_stream_ops_disabled_not_called(void)110 static inline void expect_bt_bap_stream_ops_disabled_not_called(void)
111 {
112 	const char *func_name = "bt_bap_stream_ops.disabled";
113 
114 	zexpect_call_count(func_name, 0, mock_bap_stream_disabled_cb_fake.call_count);
115 }
116 
expect_bt_bap_stream_ops_released_called(const struct bt_bap_stream * streams[],unsigned int count)117 static inline void expect_bt_bap_stream_ops_released_called(const struct bt_bap_stream *streams[],
118 							    unsigned int count)
119 {
120 	const char *func_name = "bt_bap_stream_ops.released";
121 
122 	zexpect_call_count(func_name, count, mock_bap_stream_released_cb_fake.call_count);
123 
124 	for (unsigned int i = 0; i < count; i++) {
125 		bool found = false;
126 
127 		for (unsigned int j = 0; j < mock_bap_stream_released_cb_fake.call_count; j++) {
128 			found = streams[i] == mock_bap_stream_released_cb_fake.arg0_history[j];
129 			if (found) {
130 				break;
131 			}
132 		}
133 
134 		zexpect_true(found, "'%s()' not called with %p stream", func_name, streams[i]);
135 	}
136 }
137 
expect_bt_bap_stream_ops_released_called_once(const struct bt_bap_stream * stream)138 static inline void expect_bt_bap_stream_ops_released_called_once(const struct bt_bap_stream *stream)
139 {
140 	expect_bt_bap_stream_ops_released_called(&stream, 1);
141 }
142 
expect_bt_bap_stream_ops_released_not_called(void)143 static inline void expect_bt_bap_stream_ops_released_not_called(void)
144 {
145 	const char *func_name = "bt_bap_stream_ops.released";
146 
147 	zexpect_equal(0, mock_bap_stream_released_cb_fake.call_count,
148 		      "'%s()' was called unexpectedly", func_name);
149 }
150 
expect_bt_bap_stream_ops_started_called_once(struct bt_bap_stream * stream)151 static inline void expect_bt_bap_stream_ops_started_called_once(struct bt_bap_stream *stream)
152 {
153 	const char *func_name = "bt_bap_stream_ops.started";
154 
155 	zexpect_call_count(func_name, 1, mock_bap_stream_started_cb_fake.call_count);
156 
157 	if (mock_bap_stream_started_cb_fake.call_count > 0) {
158 		zexpect_equal_ptr(stream, mock_bap_stream_started_cb_fake.arg0_val,
159 				  "'%s()' was called with incorrect '%s'", func_name, "stream");
160 	}
161 }
162 
expect_bt_bap_stream_ops_started_not_called(void)163 static inline void expect_bt_bap_stream_ops_started_not_called(void)
164 {
165 	const char *func_name = "bt_bap_stream_ops.started";
166 
167 	zexpect_call_count(func_name, 0, mock_bap_stream_started_cb_fake.call_count);
168 }
169 
170 #define expect_bt_bap_stream_ops_stopped_called_once(_stream, _reason)                             \
171 do {                                                                                               \
172 	const char *func_name = "bt_bap_stream_ops.stopped";                                       \
173 												   \
174 	zexpect_call_count(func_name, 1, mock_bap_stream_stopped_cb_fake.call_count);              \
175 												   \
176 	if (mock_bap_stream_stopped_cb_fake.call_count > 0) {                                      \
177 		IF_NOT_EMPTY(_stream, (                                                            \
178 			zexpect_equal_ptr(_stream, mock_bap_stream_stopped_cb_fake.arg0_val,       \
179 					  "'%s()' was called with incorrect '%s' value",           \
180 					  func_name, "stream");))                                  \
181 												   \
182 		IF_NOT_EMPTY(_reason, (                                                            \
183 			zexpect_equal(_reason, mock_bap_stream_stopped_cb_fake.arg1_val,           \
184 				      "'%s()' was called with incorrect '%s' value",               \
185 				      func_name, "reason");))                                      \
186 	}                                                                                          \
187 } while (0)
188 
expect_bt_bap_stream_ops_stopped_not_called(void)189 static inline void expect_bt_bap_stream_ops_stopped_not_called(void)
190 {
191 	const char *func_name = "bt_bap_stream_ops.stopped";
192 
193 	zexpect_call_count(func_name, 0, mock_bap_stream_stopped_cb_fake.call_count);
194 }
195 
196 static inline void
expect_bt_bap_stream_ops_connected_called_once(const struct bt_bap_stream * stream)197 expect_bt_bap_stream_ops_connected_called_once(const struct bt_bap_stream *stream)
198 {
199 	const char *func_name = "bt_bap_stream_ops.connected";
200 
201 	zexpect_call_count(func_name, 1, mock_bap_stream_connected_cb_fake.call_count);
202 
203 	if (mock_bap_stream_connected_cb_fake.call_count > 0) {
204 		zexpect_equal_ptr(stream, mock_bap_stream_connected_cb_fake.arg0_val,
205 				  "'%s()' was called with incorrect '%s'", func_name, "stream");
206 	}
207 }
208 
209 static inline void
expect_bt_bap_stream_ops_connected_called_twice(const struct bt_bap_stream * stream)210 expect_bt_bap_stream_ops_connected_called_twice(const struct bt_bap_stream *stream)
211 {
212 	const char *func_name = "bt_bap_stream_ops.connected";
213 
214 	zexpect_call_count(func_name, 2, mock_bap_stream_connected_cb_fake.call_count);
215 
216 	if (mock_bap_stream_connected_cb_fake.call_count > 0) {
217 		zexpect_equal_ptr(stream, mock_bap_stream_connected_cb_fake.arg0_val,
218 				  "'%s()' was called with incorrect '%s'", func_name, "stream");
219 	}
220 }
221 
222 static inline void
expect_bt_bap_stream_ops_disconnected_called_once(const struct bt_bap_stream * stream)223 expect_bt_bap_stream_ops_disconnected_called_once(const struct bt_bap_stream *stream)
224 {
225 	const char *func_name = "bt_bap_stream_ops.disconnected";
226 
227 	zexpect_call_count(func_name, 1, mock_bap_stream_disconnected_cb_fake.call_count);
228 
229 	if (mock_bap_stream_disconnected_cb_fake.call_count > 0) {
230 		zexpect_equal_ptr(stream, mock_bap_stream_disconnected_cb_fake.arg0_val,
231 				  "'%s()' was called with incorrect '%s'", func_name, "stream");
232 	}
233 }
234 
expect_bt_bap_stream_ops_recv_called_once(struct bt_bap_stream * stream,const struct bt_iso_recv_info * info,struct net_buf * buf)235 static inline void expect_bt_bap_stream_ops_recv_called_once(struct bt_bap_stream *stream,
236 							     const struct bt_iso_recv_info *info,
237 							     struct net_buf *buf)
238 {
239 	const char *func_name = "bt_bap_stream_ops.recv";
240 
241 	zexpect_call_count(func_name, 1, mock_bap_stream_recv_cb_fake.call_count);
242 
243 	if (mock_bap_stream_recv_cb_fake.call_count > 0) {
244 		zexpect_equal_ptr(stream, mock_bap_stream_recv_cb_fake.arg0_val,
245 				  "'%s()' was called with incorrect '%s'", func_name, "stream");
246 	}
247 
248 	/* TODO: validate info && buf */
249 }
250 
expect_bt_bap_stream_ops_recv_not_called(void)251 static inline void expect_bt_bap_stream_ops_recv_not_called(void)
252 {
253 	const char *func_name = "bt_bap_stream_ops.recv";
254 
255 	zexpect_call_count(func_name, 0, mock_bap_stream_recv_cb_fake.call_count);
256 }
257 
expect_bt_bap_stream_ops_sent_called_once(struct bt_bap_stream * stream)258 static inline void expect_bt_bap_stream_ops_sent_called_once(struct bt_bap_stream *stream)
259 {
260 	const char *func_name = "bt_bap_stream_ops.sent";
261 
262 	zexpect_call_count(func_name, 1, mock_bap_stream_sent_cb_fake.call_count);
263 
264 	if (mock_bap_stream_sent_cb_fake.call_count > 0) {
265 		zexpect_equal_ptr(stream, mock_bap_stream_sent_cb_fake.arg0_val,
266 				  "'%s()' was called with incorrect '%s'", func_name, "stream");
267 	}
268 }
269 
expect_bt_bap_stream_ops_sent_not_called(void)270 static inline void expect_bt_bap_stream_ops_sent_not_called(void)
271 {
272 	const char *func_name = "bt_bap_stream_ops.sent";
273 
274 	zexpect_call_count(func_name, 0, mock_bap_stream_sent_cb_fake.call_count);
275 }
276 
277 #endif /* MOCKS_BAP_STREAM_EXPECTS_H_ */
278