1 /* test_callback_register.c - Test bt_bap_broadcast_source_register and unregister */
2
3 /*
4 * Copyright (c) 2024 Nordic Semiconductor ASA
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9 #include <errno.h>
10 #include <stddef.h>
11
12 #include <zephyr/bluetooth/audio/bap.h>
13 #include <zephyr/fff.h>
14
15 #include "bap_broadcast_source.h"
16 #include "ztest_assert.h"
17 #include "ztest_test.h"
18
19 #define FFF_GLOBALS
20
mock_init_rule_before(const struct ztest_unit_test * test,void * fixture)21 static void mock_init_rule_before(const struct ztest_unit_test *test, void *fixture)
22 {
23 mock_bap_broadcast_source_init();
24 }
25
26 ZTEST_RULE(mock_rule, mock_init_rule_before, NULL);
27
bap_broadcast_source_test_cb_register_suite_after(void * f)28 static void bap_broadcast_source_test_cb_register_suite_after(void *f)
29 {
30 bt_bap_broadcast_source_unregister_cb(&mock_bap_broadcast_source_cb);
31 }
32
33 ZTEST_SUITE(bap_broadcast_source_test_cb_register_suite, NULL, NULL, NULL,
34 bap_broadcast_source_test_cb_register_suite_after, NULL);
35
ZTEST(bap_broadcast_source_test_cb_register_suite,test_broadcast_source_register_cb)36 static ZTEST(bap_broadcast_source_test_cb_register_suite, test_broadcast_source_register_cb)
37 {
38 int err;
39
40 err = bt_bap_broadcast_source_register_cb(&mock_bap_broadcast_source_cb);
41 zassert_equal(0, err, "Unexpected return value %d", err);
42 }
43
ZTEST(bap_broadcast_source_test_cb_register_suite,test_broadcast_source_register_cb_inval_param_null)44 static ZTEST(bap_broadcast_source_test_cb_register_suite,
45 test_broadcast_source_register_cb_inval_param_null)
46 {
47 int err;
48
49 err = bt_bap_broadcast_source_register_cb(NULL);
50 zassert_equal(err, -EINVAL, "Unexpected return value %d", err);
51 }
52
ZTEST(bap_broadcast_source_test_cb_register_suite,test_broadcast_source_register_cb_inval_double_register)53 static ZTEST(bap_broadcast_source_test_cb_register_suite,
54 test_broadcast_source_register_cb_inval_double_register)
55 {
56 int err;
57
58 err = bt_bap_broadcast_source_register_cb(&mock_bap_broadcast_source_cb);
59 zassert_equal(err, 0, "Unexpected return value %d", err);
60
61 err = bt_bap_broadcast_source_register_cb(&mock_bap_broadcast_source_cb);
62 zassert_equal(err, -EEXIST, "Unexpected return value %d", err);
63 }
64
ZTEST(bap_broadcast_source_test_cb_register_suite,test_broadcast_source_unregister_cb)65 static ZTEST(bap_broadcast_source_test_cb_register_suite, test_broadcast_source_unregister_cb)
66 {
67 int err;
68
69 err = bt_bap_broadcast_source_register_cb(&mock_bap_broadcast_source_cb);
70 zassert_equal(err, 0, "Unexpected return value %d", err);
71
72 err = bt_bap_broadcast_source_unregister_cb(&mock_bap_broadcast_source_cb);
73 zassert_equal(err, 0, "Unexpected return value %d", err);
74 }
75
ZTEST(bap_broadcast_source_test_cb_register_suite,test_broadcast_source_unregister_cb_inval_param_null)76 static ZTEST(bap_broadcast_source_test_cb_register_suite,
77 test_broadcast_source_unregister_cb_inval_param_null)
78 {
79 int err;
80
81 err = bt_bap_broadcast_source_unregister_cb(NULL);
82 zassert_equal(err, -EINVAL, "Unexpected return value %d", err);
83 }
84
ZTEST(bap_broadcast_source_test_cb_register_suite,test_broadcast_source_unregister_cb_inval_double_unregister)85 static ZTEST(bap_broadcast_source_test_cb_register_suite,
86 test_broadcast_source_unregister_cb_inval_double_unregister)
87 {
88 int err;
89
90 err = bt_bap_broadcast_source_register_cb(&mock_bap_broadcast_source_cb);
91 zassert_equal(err, 0, "Unexpected return value %d", err);
92
93 err = bt_bap_broadcast_source_unregister_cb(&mock_bap_broadcast_source_cb);
94 zassert_equal(err, 0, "Unexpected return value %d", err);
95
96 err = bt_bap_broadcast_source_unregister_cb(&mock_bap_broadcast_source_cb);
97 zassert_equal(err, -ENOENT, "Unexpected return value %d", err);
98 }
99