1 /* test_broadcast_reception.c - unit test for broadcast reception start and stop */
2 
3 /*
4  * Copyright (c) 2024 Nordic Semiconductor ASA
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #include <stdlib.h>
10 
11 #include <zephyr/bluetooth/audio/cap.h>
12 #include <zephyr/fff.h>
13 
14 #include "bluetooth.h"
15 #include "cap_commander.h"
16 #include "conn.h"
17 #include "expects_util.h"
18 #include "cap_mocks.h"
19 #include "test_common.h"
20 
21 #include <zephyr/logging/log.h>
22 
23 LOG_MODULE_REGISTER(bt_broadcast_reception_test, CONFIG_BT_CAP_COMMANDER_LOG_LEVEL);
24 
25 #define FFF_GLOBALS
26 
27 #define SID          0x0E
28 #define ADV_INTERVAL 10
29 #define BROADCAST_ID 0x55AA55
30 
31 struct cap_commander_test_broadcast_reception_fixture {
32 	struct bt_conn conns[CONFIG_BT_MAX_CONN];
33 
34 	struct bt_bap_bass_subgroup subgroups[CONFIG_BT_BAP_BASS_MAX_SUBGROUPS];
35 	struct bt_cap_commander_broadcast_reception_start_member_param
36 		start_member_params[CONFIG_BT_MAX_CONN];
37 	struct bt_cap_commander_broadcast_reception_start_param start_param;
38 	struct bt_cap_commander_broadcast_reception_stop_member_param
39 		stop_member_params[CONFIG_BT_MAX_CONN];
40 	struct bt_cap_commander_broadcast_reception_stop_param stop_param;
41 	struct bt_bap_broadcast_assistant_cb broadcast_assistant_cb;
42 };
43 
44 /* src_id can not be part of the fixture since it is accessed in the callback function */
45 static uint8_t src_id[CONFIG_BT_MAX_CONN];
46 
47 static void test_start_param_init(void *f);
48 static void test_stop_param_init(void *f);
49 
cap_commander_broadcast_assistant_recv_state_cb(struct bt_conn * conn,int err,const struct bt_bap_scan_delegator_recv_state * state)50 static void cap_commander_broadcast_assistant_recv_state_cb(
51 	struct bt_conn *conn, int err, const struct bt_bap_scan_delegator_recv_state *state)
52 {
53 	uint8_t index;
54 
55 	index = bt_conn_index(conn);
56 	src_id[index] = state->src_id;
57 }
58 
cap_commander_test_broadcast_reception_fixture_init(struct cap_commander_test_broadcast_reception_fixture * fixture)59 static void cap_commander_test_broadcast_reception_fixture_init(
60 	struct cap_commander_test_broadcast_reception_fixture *fixture)
61 {
62 	int err;
63 
64 	for (size_t i = 0; i < ARRAY_SIZE(fixture->conns); i++) {
65 		test_conn_init(&fixture->conns[i]);
66 		fixture->conns[i].index = i;
67 	}
68 	test_start_param_init(fixture);
69 	test_stop_param_init(fixture);
70 
71 	fixture->broadcast_assistant_cb.recv_state =
72 		cap_commander_broadcast_assistant_recv_state_cb;
73 	err = bt_bap_broadcast_assistant_register_cb(&fixture->broadcast_assistant_cb);
74 	zassert_equal(0, err, "Failed registering broadcast assistant callback functions %d", err);
75 }
76 
cap_commander_test_broadcast_reception_setup(void)77 static void *cap_commander_test_broadcast_reception_setup(void)
78 {
79 	struct cap_commander_test_broadcast_reception_fixture *fixture;
80 
81 	fixture = malloc(sizeof(*fixture));
82 	zassert_not_null(fixture);
83 
84 	return fixture;
85 }
86 
cap_commander_test_broadcast_reception_before(void * f)87 static void cap_commander_test_broadcast_reception_before(void *f)
88 {
89 	int err;
90 	struct cap_commander_test_broadcast_reception_fixture *fixture = f;
91 
92 	memset(f, 0, sizeof(struct cap_commander_test_broadcast_reception_fixture));
93 	cap_commander_test_broadcast_reception_fixture_init(fixture);
94 
95 	for (size_t i = 0; i < ARRAY_SIZE(fixture->conns); i++) {
96 		err = bt_cap_commander_discover(&fixture->conns[i]);
97 		zassert_equal(0, err, "Unexpected return value %d", err);
98 	}
99 }
100 
cap_commander_test_broadcast_reception_after(void * f)101 static void cap_commander_test_broadcast_reception_after(void *f)
102 {
103 	struct cap_commander_test_broadcast_reception_fixture *fixture = f;
104 
105 	bt_cap_commander_unregister_cb(&mock_cap_commander_cb);
106 	bt_bap_broadcast_assistant_unregister_cb(&fixture->broadcast_assistant_cb);
107 
108 	/* We need to cleanup since the CAP commander remembers state */
109 	(void)bt_cap_commander_cancel();
110 
111 	for (size_t i = 0; i < ARRAY_SIZE(fixture->conns); i++) {
112 		mock_bt_conn_disconnected(&fixture->conns[i], BT_HCI_ERR_REMOTE_USER_TERM_CONN);
113 	}
114 }
115 
cap_commander_test_broadcast_reception_teardown(void * f)116 static void cap_commander_test_broadcast_reception_teardown(void *f)
117 {
118 	free(f);
119 }
120 
test_start_param_init(void * f)121 static void test_start_param_init(void *f)
122 {
123 	struct cap_commander_test_broadcast_reception_fixture *fixture = f;
124 	int err;
125 
126 	fixture->start_param.type = BT_CAP_SET_TYPE_AD_HOC;
127 	fixture->start_param.param = fixture->start_member_params;
128 
129 	fixture->start_param.count = ARRAY_SIZE(fixture->start_member_params);
130 
131 	for (size_t i = 0; i < ARRAY_SIZE(fixture->subgroups); i++) {
132 		fixture->subgroups[i].bis_sync = 1 << i;
133 		fixture->subgroups[i].metadata_len = 0;
134 	}
135 
136 	for (size_t i = 0U; i < ARRAY_SIZE(fixture->start_member_params); i++) {
137 		fixture->start_member_params[i].member.member = &fixture->conns[i];
138 		bt_addr_le_copy(&fixture->start_member_params[i].addr, BT_ADDR_LE_ANY);
139 		fixture->start_member_params[i].adv_sid = SID;
140 		fixture->start_member_params[i].pa_interval = ADV_INTERVAL;
141 		fixture->start_member_params[i].broadcast_id = BROADCAST_ID;
142 		memcpy(fixture->start_member_params[i].subgroups, &fixture->subgroups[0],
143 		       sizeof(struct bt_bap_bass_subgroup) * CONFIG_BT_BAP_BASS_MAX_SUBGROUPS);
144 		fixture->start_member_params[i].num_subgroups = CONFIG_BT_BAP_BASS_MAX_SUBGROUPS;
145 	}
146 
147 	for (size_t i = 0; i < ARRAY_SIZE(fixture->conns); i++) {
148 		err = bt_cap_commander_discover(&fixture->conns[i]);
149 		zassert_equal(0, err, "Unexpected return value %d", err);
150 	}
151 }
152 
test_stop_param_init(void * f)153 static void test_stop_param_init(void *f)
154 {
155 	struct cap_commander_test_broadcast_reception_fixture *fixture = f;
156 
157 	fixture->stop_param.type = BT_CAP_SET_TYPE_AD_HOC;
158 	fixture->stop_param.param = fixture->stop_member_params;
159 	fixture->stop_param.count = ARRAY_SIZE(fixture->stop_member_params);
160 
161 	for (size_t i = 0U; i < ARRAY_SIZE(fixture->stop_member_params); i++) {
162 		fixture->stop_member_params[i].member.member = &fixture->conns[i];
163 		fixture->stop_member_params[i].src_id = 0;
164 		fixture->stop_member_params[i].num_subgroups = CONFIG_BT_BAP_BASS_MAX_SUBGROUPS;
165 	}
166 }
167 
168 static void
test_broadcast_reception_start(struct bt_cap_commander_broadcast_reception_start_param * start_param)169 test_broadcast_reception_start(struct bt_cap_commander_broadcast_reception_start_param *start_param)
170 {
171 	int err;
172 
173 	err = bt_cap_commander_broadcast_reception_start(start_param);
174 	zassert_equal(0, err, "Unexpected return value %d", err);
175 
176 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_start", 1,
177 			   mock_cap_commander_broadcast_reception_start_cb_fake.call_count);
178 	zassert_equal_ptr(NULL,
179 			  mock_cap_commander_broadcast_reception_start_cb_fake.arg0_history[0]);
180 	zassert_equal(0, mock_cap_commander_broadcast_reception_start_cb_fake.arg1_history[0]);
181 }
182 
183 static void
test_broadcast_reception_stop(struct bt_cap_commander_broadcast_reception_stop_param * stop_param)184 test_broadcast_reception_stop(struct bt_cap_commander_broadcast_reception_stop_param *stop_param)
185 {
186 	int err;
187 
188 	err = bt_cap_commander_broadcast_reception_stop(stop_param);
189 	zassert_equal(0, err, "Unexpected return value %d", err);
190 
191 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_stop", 1,
192 			   mock_cap_commander_broadcast_reception_stop_cb_fake.call_count);
193 	zassert_equal_ptr(NULL,
194 			  mock_cap_commander_broadcast_reception_stop_cb_fake.arg0_history[0]);
195 	zassert_equal(0, mock_cap_commander_broadcast_reception_stop_cb_fake.arg1_history[0]);
196 }
197 
198 ZTEST_SUITE(cap_commander_test_broadcast_reception, NULL,
199 	    cap_commander_test_broadcast_reception_setup,
200 	    cap_commander_test_broadcast_reception_before,
201 	    cap_commander_test_broadcast_reception_after,
202 	    cap_commander_test_broadcast_reception_teardown);
203 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start)204 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_start)
205 {
206 	int err;
207 
208 	err = bt_cap_commander_register_cb(&mock_cap_commander_cb);
209 	zassert_equal(0, err, "Unexpected return value %d", err);
210 
211 	test_broadcast_reception_start(&fixture->start_param);
212 }
213 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start_one_subgroup)214 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_start_one_subgroup)
215 {
216 	int err;
217 
218 	err = bt_cap_commander_register_cb(&mock_cap_commander_cb);
219 	zassert_equal(0, err, "Unexpected return value %d", err);
220 
221 	/* We test with one subgroup, instead of CONFIG_BT_BAP_BASS_MAX_SUBGROUPS subgroups */
222 	for (size_t i = 0U; i < CONFIG_BT_MAX_CONN; i++) {
223 		fixture->start_param.param[i].num_subgroups = 1;
224 	}
225 
226 	test_broadcast_reception_start(&fixture->start_param);
227 }
228 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start_double)229 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_start_double)
230 {
231 	int err;
232 
233 	err = bt_cap_commander_register_cb(&mock_cap_commander_cb);
234 	zassert_equal(0, err, "Unexpected return value %d", err);
235 
236 	test_broadcast_reception_start(&fixture->start_param);
237 
238 	/*
239 	 * We can not use test_broadcast_reception_start because of the check on how often the
240 	 * callback function is called
241 	 */
242 	err = bt_cap_commander_broadcast_reception_start(&fixture->start_param);
243 	zassert_equal(0, err, "Unexpected return value %d", err);
244 
245 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_start", 2,
246 			   mock_cap_commander_broadcast_reception_start_cb_fake.call_count);
247 }
248 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start_inval_param_null)249 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_start_inval_param_null)
250 {
251 	int err;
252 
253 	err = bt_cap_commander_broadcast_reception_start(NULL);
254 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
255 
256 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_start", 0,
257 			   mock_cap_commander_broadcast_reception_start_cb_fake.call_count);
258 }
259 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start_inval_param_zero_count)260 ZTEST_F(cap_commander_test_broadcast_reception,
261 	test_commander_reception_start_inval_param_zero_count)
262 {
263 	int err;
264 
265 	fixture->start_param.count = 0;
266 
267 	err = bt_cap_commander_broadcast_reception_start(&fixture->start_param);
268 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
269 
270 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_start", 0,
271 			   mock_cap_commander_broadcast_reception_start_cb_fake.call_count);
272 }
273 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start_inval_param_high_count)274 ZTEST_F(cap_commander_test_broadcast_reception,
275 	test_commander_reception_start_inval_param_high_count)
276 {
277 	int err;
278 
279 	fixture->start_param.count = CONFIG_BT_MAX_CONN + 1;
280 
281 	err = bt_cap_commander_broadcast_reception_start(&fixture->start_param);
282 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
283 
284 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_start", 0,
285 			   mock_cap_commander_broadcast_reception_start_cb_fake.call_count);
286 }
287 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start_inval_param_null_param)288 ZTEST_F(cap_commander_test_broadcast_reception,
289 	test_commander_reception_start_inval_param_null_param)
290 {
291 	int err;
292 
293 	fixture->start_param.type = BT_CAP_SET_TYPE_AD_HOC;
294 	fixture->start_param.param = NULL;
295 	fixture->start_param.count = ARRAY_SIZE(fixture->conns);
296 
297 	err = bt_cap_commander_broadcast_reception_start(&fixture->start_param);
298 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
299 
300 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_start", 0,
301 			   mock_cap_commander_broadcast_reception_start_cb_fake.call_count);
302 }
303 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start_inval_null_member)304 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_start_inval_null_member)
305 {
306 	int err;
307 
308 	fixture->start_param.param[0].member.member = NULL;
309 
310 	err = bt_cap_commander_broadcast_reception_start(&fixture->start_param);
311 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
312 
313 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_start", 0,
314 			   mock_cap_commander_broadcast_reception_start_cb_fake.call_count);
315 }
316 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start_inval_missing_cas)317 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_start_inval_missing_cas)
318 {
319 	int err;
320 
321 	fixture->start_param.type = BT_CAP_SET_TYPE_CSIP;
322 
323 	err = bt_cap_commander_broadcast_reception_start(&fixture->start_param);
324 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
325 
326 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_start", 0,
327 			   mock_cap_commander_broadcast_reception_start_cb_fake.call_count);
328 }
329 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start_inval_addr_type)330 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_start_inval_addr_type)
331 {
332 	int err;
333 
334 	fixture->start_param.param[0].addr.type = BT_ADDR_LE_RANDOM + 1;
335 
336 	err = bt_cap_commander_broadcast_reception_start(&fixture->start_param);
337 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
338 
339 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_start", 0,
340 			   mock_cap_commander_broadcast_reception_start_cb_fake.call_count);
341 }
342 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start_inval_sid)343 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_start_inval_sid)
344 {
345 	int err;
346 
347 	fixture->start_param.param[0].adv_sid = BT_GAP_SID_MAX + 1;
348 
349 	err = bt_cap_commander_broadcast_reception_start(&fixture->start_param);
350 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
351 
352 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_start", 0,
353 			   mock_cap_commander_broadcast_reception_start_cb_fake.call_count);
354 }
355 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start_inval_pa_interval_low)356 ZTEST_F(cap_commander_test_broadcast_reception,
357 	test_commander_reception_start_inval_pa_interval_low)
358 {
359 	int err;
360 
361 	fixture->start_param.param[0].pa_interval = BT_GAP_PER_ADV_MIN_INTERVAL - 1;
362 
363 	err = bt_cap_commander_broadcast_reception_start(&fixture->start_param);
364 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
365 
366 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_start", 0,
367 			   mock_cap_commander_broadcast_reception_start_cb_fake.call_count);
368 }
369 
370 /*
371  * Test for pa_interval_high omitted
372  * pa_interval is a uint16_t, BT_GAP_PER_ADV_MAX_INTERVAL is defined as 0xFFFF
373  * and therefor we can not test in the current implementation
374  */
375 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start_inval_broadcast_id)376 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_start_inval_broadcast_id)
377 {
378 	int err;
379 
380 	fixture->start_param.param[0].broadcast_id = BT_AUDIO_BROADCAST_ID_MAX + 1;
381 
382 	err = bt_cap_commander_broadcast_reception_start(&fixture->start_param);
383 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
384 
385 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_start", 0,
386 			   mock_cap_commander_broadcast_reception_start_cb_fake.call_count);
387 }
388 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start_inval_no_subgroups)389 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_start_inval_no_subgroups)
390 {
391 	int err;
392 
393 	fixture->start_param.param[0].num_subgroups = 0;
394 
395 	err = bt_cap_commander_broadcast_reception_start(&fixture->start_param);
396 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
397 
398 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_start", 0,
399 			   mock_cap_commander_broadcast_reception_start_cb_fake.call_count);
400 }
401 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start_inval_num_subgroups)402 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_start_inval_num_subgroups)
403 {
404 	int err;
405 
406 	fixture->start_param.param[0].num_subgroups = CONFIG_BT_BAP_BASS_MAX_SUBGROUPS + 1;
407 
408 	err = bt_cap_commander_broadcast_reception_start(&fixture->start_param);
409 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
410 
411 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_start", 0,
412 			   mock_cap_commander_broadcast_reception_start_cb_fake.call_count);
413 }
414 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start_inval_duplicate_bis_sync)415 ZTEST_F(cap_commander_test_broadcast_reception,
416 	test_commander_reception_start_inval_duplicate_bis_sync)
417 {
418 	int err;
419 
420 	if (CONFIG_BT_BAP_BASS_MAX_SUBGROUPS == 1) {
421 		ztest_test_skip();
422 	}
423 
424 	fixture->start_param.param[0].subgroups[0].bis_sync =
425 		fixture->start_param.param[0].subgroups[1].bis_sync;
426 
427 	err = bt_cap_commander_broadcast_reception_start(&fixture->start_param);
428 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
429 
430 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_start", 0,
431 			   mock_cap_commander_broadcast_reception_start_cb_fake.call_count);
432 }
433 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_start_inval_metadata_len)434 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_start_inval_metadata_len)
435 {
436 	int err;
437 
438 	fixture->start_param.param[0].subgroups[0].metadata_len =
439 		CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE + 1;
440 
441 	err = bt_cap_commander_broadcast_reception_start(&fixture->start_param);
442 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
443 
444 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_start", 0,
445 			   mock_cap_commander_broadcast_reception_start_cb_fake.call_count);
446 }
447 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_stop_default_subgroups)448 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_stop_default_subgroups)
449 {
450 	int err;
451 
452 	err = bt_cap_commander_register_cb(&mock_cap_commander_cb);
453 	zassert_equal(0, err, "Unexpected return value %d", err);
454 
455 	test_broadcast_reception_start(&fixture->start_param);
456 
457 	for (size_t i = 0U; i < CONFIG_BT_MAX_CONN; i++) {
458 		fixture->stop_param.param[i].src_id = src_id[i];
459 	}
460 
461 	test_broadcast_reception_stop(&fixture->stop_param);
462 }
463 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_stop_one_subgroup)464 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_stop_one_subgroup)
465 {
466 	int err;
467 
468 	err = bt_cap_commander_register_cb(&mock_cap_commander_cb);
469 	zassert_equal(0, err, "Unexpected return value %d", err);
470 
471 	test_broadcast_reception_start(&fixture->start_param);
472 
473 	/* We test with one subgroup, instead of CONFIG_BT_BAP_BASS_MAX_SUBGROUPS subgroups */
474 	for (size_t i = 0U; i < CONFIG_BT_MAX_CONN; i++) {
475 		fixture->stop_param.param[i].num_subgroups = 1;
476 		fixture->stop_param.param[i].src_id = src_id[i];
477 	}
478 
479 	test_broadcast_reception_stop(&fixture->stop_param);
480 }
481 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_stop_double)482 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_stop_double)
483 {
484 	int err;
485 
486 	err = bt_cap_commander_register_cb(&mock_cap_commander_cb);
487 	zassert_equal(0, err, "Unexpected return value %d", err);
488 
489 	test_broadcast_reception_start(&fixture->start_param);
490 
491 	for (size_t i = 0U; i < CONFIG_BT_MAX_CONN; i++) {
492 		printk("Source ID %d: %d %d\n", i, fixture->stop_param.param[i].src_id, src_id[i]);
493 
494 		fixture->stop_param.param[i].src_id = src_id[i];
495 	}
496 
497 	test_broadcast_reception_stop(&fixture->stop_param);
498 
499 	/*
500 	 * We can not use test_broadcast_reception_stop because of the check on how often the
501 	 * callback function is called
502 	 */
503 	err = bt_cap_commander_broadcast_reception_stop(&fixture->stop_param);
504 	zassert_equal(0, err, "Unexpected return value %d", err);
505 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_stop", 2,
506 			   mock_cap_commander_broadcast_reception_stop_cb_fake.call_count);
507 }
508 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_stop_inval_param_null)509 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_stop_inval_param_null)
510 {
511 	int err;
512 
513 	err = bt_cap_commander_broadcast_reception_stop(NULL);
514 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
515 
516 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_stop", 0,
517 			   mock_cap_commander_broadcast_reception_stop_cb_fake.call_count);
518 }
519 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_stop_inval_param_zero_count)520 ZTEST_F(cap_commander_test_broadcast_reception,
521 	test_commander_reception_stop_inval_param_zero_count)
522 {
523 	int err;
524 
525 	fixture->stop_param.count = 0;
526 
527 	err = bt_cap_commander_broadcast_reception_stop(&fixture->stop_param);
528 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
529 
530 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_stop", 0,
531 			   mock_cap_commander_broadcast_reception_stop_cb_fake.call_count);
532 }
533 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_stop_inval_param_high_count)534 ZTEST_F(cap_commander_test_broadcast_reception,
535 	test_commander_reception_stop_inval_param_high_count)
536 {
537 	int err;
538 
539 	fixture->stop_param.count = CONFIG_BT_MAX_CONN + 1;
540 
541 	err = bt_cap_commander_broadcast_reception_stop(&fixture->stop_param);
542 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
543 
544 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_stop", 0,
545 			   mock_cap_commander_broadcast_reception_stop_cb_fake.call_count);
546 }
547 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_stop_inval_param_null_param)548 ZTEST_F(cap_commander_test_broadcast_reception,
549 	test_commander_reception_stop_inval_param_null_param)
550 {
551 	int err;
552 
553 	fixture->stop_param.type = BT_CAP_SET_TYPE_AD_HOC;
554 	fixture->stop_param.param = NULL;
555 	fixture->stop_param.count = ARRAY_SIZE(fixture->conns);
556 
557 	err = bt_cap_commander_broadcast_reception_stop(&fixture->stop_param);
558 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
559 
560 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_stop", 0,
561 			   mock_cap_commander_broadcast_reception_stop_cb_fake.call_count);
562 }
563 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_stop_inval_null_member)564 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_stop_inval_null_member)
565 {
566 	int err;
567 
568 	fixture->stop_param.param[0].member.member = NULL;
569 
570 	err = bt_cap_commander_broadcast_reception_stop(&fixture->stop_param);
571 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
572 
573 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_stop", 0,
574 			   mock_cap_commander_broadcast_reception_stop_cb_fake.call_count);
575 }
576 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_stop_inval_missing_cas)577 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_stop_inval_missing_cas)
578 {
579 	int err;
580 
581 	fixture->stop_param.type = BT_CAP_SET_TYPE_CSIP;
582 
583 	err = bt_cap_commander_broadcast_reception_stop(&fixture->stop_param);
584 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
585 
586 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_stop", 0,
587 			   mock_cap_commander_broadcast_reception_stop_cb_fake.call_count);
588 }
589 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_stop_inval_no_subgroups)590 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_stop_inval_no_subgroups)
591 {
592 	int err;
593 
594 	fixture->stop_param.param[0].num_subgroups = 0;
595 
596 	err = bt_cap_commander_broadcast_reception_stop(&fixture->stop_param);
597 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
598 
599 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_stop", 0,
600 			   mock_cap_commander_broadcast_reception_stop_cb_fake.call_count);
601 }
602 
ZTEST_F(cap_commander_test_broadcast_reception,test_commander_reception_stop_inval_num_subgroups)603 ZTEST_F(cap_commander_test_broadcast_reception, test_commander_reception_stop_inval_num_subgroups)
604 {
605 	int err;
606 
607 	fixture->stop_param.param[0].num_subgroups = CONFIG_BT_BAP_BASS_MAX_SUBGROUPS + 1;
608 
609 	err = bt_cap_commander_broadcast_reception_stop(&fixture->stop_param);
610 	zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
611 
612 	zexpect_call_count("bt_cap_commander_cb.broadcast_reception_stop", 0,
613 			   mock_cap_commander_broadcast_reception_stop_cb_fake.call_count);
614 }
615