1 /* main.c - Application main entry point */
2
3 /*
4 * Copyright (c) 2023 Codecoup
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9 #include <errno.h>
10 #include <stdbool.h>
11 #include <stddef.h>
12 #include <stdint.h>
13
14 #include <zephyr/bluetooth/audio/audio.h>
15 #include <zephyr/bluetooth/audio/bap_lc3_preset.h>
16 #include <zephyr/bluetooth/audio/lc3.h>
17 #include <zephyr/bluetooth/byteorder.h>
18 #include <zephyr/bluetooth/hci_types.h>
19 #include <zephyr/fff.h>
20 #include <zephyr/sys/byteorder.h>
21 #include <zephyr/sys/util.h>
22
23 #include <ztest_test.h>
24 #include <ztest_assert.h>
25
26 DEFINE_FFF_GLOBALS;
27
28 ZTEST_SUITE(audio_codec_test_suite, NULL, NULL, NULL, NULL, NULL);
29
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_get_val)30 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_val)
31 {
32 struct bt_audio_codec_cfg codec_cfg =
33 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000,
34 {BT_AUDIO_CODEC_DATA(BT_AUDIO_CODEC_CFG_FREQ,
35 BT_AUDIO_CODEC_CFG_FREQ_16KHZ)},
36 {});
37 const uint8_t expected_data = BT_AUDIO_CODEC_CFG_FREQ_16KHZ;
38 const uint8_t *data;
39 int ret;
40
41 ret = bt_audio_codec_cfg_get_val(&codec_cfg, BT_AUDIO_CODEC_CFG_FREQ, &data);
42 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
43 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
44 }
45
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_set_val)46 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_set_val)
47 {
48 struct bt_audio_codec_cfg codec_cfg =
49 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000,
50 {BT_AUDIO_CODEC_DATA(BT_AUDIO_CODEC_CFG_FREQ,
51 BT_AUDIO_CODEC_CFG_FREQ_16KHZ)},
52 {});
53 const uint8_t new_expected_data = BT_AUDIO_CODEC_CFG_FREQ_48KHZ;
54 const uint8_t expected_data = BT_AUDIO_CODEC_CFG_FREQ_16KHZ;
55 const uint8_t *data;
56 int ret;
57
58 ret = bt_audio_codec_cfg_get_val(&codec_cfg, BT_AUDIO_CODEC_CFG_FREQ, &data);
59 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
60 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
61
62 ret = bt_audio_codec_cfg_set_val(&codec_cfg, BT_AUDIO_CODEC_CFG_FREQ,
63 &new_expected_data, sizeof(new_expected_data));
64 zassert_true(ret > 0, "Unexpected return value %d", ret);
65
66 ret = bt_audio_codec_cfg_get_val(&codec_cfg, BT_AUDIO_CODEC_CFG_FREQ, &data);
67 zassert_equal(ret, sizeof(new_expected_data), "Unexpected return value %d", ret);
68 zassert_equal(data[0], new_expected_data, "Unexpected data value %u", data[0]);
69 }
70
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_set_val_new_value)71 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_set_val_new_value)
72 {
73 struct bt_audio_codec_cfg codec_cfg =
74 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, {});
75 const uint8_t new_expected_data = BT_AUDIO_CODEC_CFG_FREQ_48KHZ;
76 const uint8_t *data;
77 int ret;
78
79 ret = bt_audio_codec_cfg_get_val(&codec_cfg, BT_AUDIO_CODEC_CFG_FREQ, &data);
80 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
81
82 ret = bt_audio_codec_cfg_set_val(&codec_cfg, BT_AUDIO_CODEC_CFG_FREQ,
83 &new_expected_data, sizeof(new_expected_data));
84 zassert_true(ret > 0, "Unexpected return value %d", ret);
85
86 ret = bt_audio_codec_cfg_get_val(&codec_cfg, BT_AUDIO_CODEC_CFG_FREQ, &data);
87 zassert_equal(ret, sizeof(new_expected_data), "Unexpected return value %d", ret);
88 zassert_equal(data[0], new_expected_data, "Unexpected return value %d", ret);
89 }
90
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_unset_val)91 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_unset_val)
92 {
93 struct bt_audio_codec_cfg codec_cfg =
94 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000,
95 {BT_AUDIO_CODEC_DATA(BT_AUDIO_CODEC_CFG_FREQ,
96 BT_AUDIO_CODEC_CFG_FREQ_16KHZ)},
97 {});
98 const uint8_t expected_data = BT_AUDIO_CODEC_CFG_FREQ_16KHZ;
99 const uint8_t *data;
100 int ret;
101
102 ret = bt_audio_codec_cfg_get_val(&codec_cfg, BT_AUDIO_CODEC_CFG_FREQ, &data);
103 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
104 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
105
106 ret = bt_audio_codec_cfg_unset_val(&codec_cfg, BT_AUDIO_CODEC_CFG_FREQ);
107 zassert_true(ret >= 0, "Unexpected return value %d", ret);
108
109 ret = bt_audio_codec_cfg_get_val(&codec_cfg, BT_AUDIO_CODEC_CFG_FREQ, &data);
110 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
111 }
112
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_freq_to_freq_hz)113 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_freq_to_freq_hz)
114 {
115 const struct freq_test_input {
116 enum bt_audio_codec_cfg_freq freq;
117 uint32_t freq_hz;
118 } freq_test_inputs[] = {
119 {.freq = BT_AUDIO_CODEC_CFG_FREQ_8KHZ, .freq_hz = 8000U},
120 {.freq = BT_AUDIO_CODEC_CFG_FREQ_11KHZ, .freq_hz = 11025U},
121 {.freq = BT_AUDIO_CODEC_CFG_FREQ_16KHZ, .freq_hz = 16000U},
122 {.freq = BT_AUDIO_CODEC_CFG_FREQ_22KHZ, .freq_hz = 22050U},
123 {.freq = BT_AUDIO_CODEC_CFG_FREQ_24KHZ, .freq_hz = 24000U},
124 {.freq = BT_AUDIO_CODEC_CFG_FREQ_32KHZ, .freq_hz = 32000U},
125 {.freq = BT_AUDIO_CODEC_CFG_FREQ_44KHZ, .freq_hz = 44100U},
126 {.freq = BT_AUDIO_CODEC_CFG_FREQ_48KHZ, .freq_hz = 48000U},
127 {.freq = BT_AUDIO_CODEC_CFG_FREQ_88KHZ, .freq_hz = 88200U},
128 {.freq = BT_AUDIO_CODEC_CFG_FREQ_96KHZ, .freq_hz = 96000U},
129 {.freq = BT_AUDIO_CODEC_CFG_FREQ_176KHZ, .freq_hz = 176400U},
130 {.freq = BT_AUDIO_CODEC_CFG_FREQ_192KHZ, .freq_hz = 192000U},
131 {.freq = BT_AUDIO_CODEC_CFG_FREQ_384KHZ, .freq_hz = 384000U},
132 };
133
134 for (size_t i = 0U; i < ARRAY_SIZE(freq_test_inputs); i++) {
135 const struct freq_test_input *fti = &freq_test_inputs[i];
136
137 zassert_equal(bt_audio_codec_cfg_freq_to_freq_hz(fti->freq), fti->freq_hz,
138 "freq %d was not coverted to %u", fti->freq, fti->freq_hz);
139 zassert_equal(bt_audio_codec_cfg_freq_hz_to_freq(fti->freq_hz), fti->freq,
140 "freq_hz %u was not coverted to %d", fti->freq_hz, fti->freq);
141 }
142 }
143
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_get_freq)144 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_freq)
145 {
146 const struct bt_bap_lc3_preset preset =
147 BT_BAP_LC3_UNICAST_PRESET_16_2_1(BT_AUDIO_LOCATION_FRONT_LEFT,
148 BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
149 int ret;
150
151 ret = bt_audio_codec_cfg_get_freq(&preset.codec_cfg);
152 zassert_equal(ret, 0x03, "unexpected return value %d", ret);
153 }
154
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_set_val_new)155 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_set_val_new)
156 {
157 struct bt_bap_lc3_preset preset = BT_BAP_LC3_UNICAST_PRESET_16_2_1(
158 BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
159 const uint8_t frame_blocks = 0x02;
160 int ret;
161
162 /* Frame blocks are not part of the preset, so we can use that to test adding a new type to
163 * the config
164 */
165 ret = bt_audio_codec_cfg_get_frame_blocks_per_sdu(&preset.codec_cfg, false);
166 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
167
168 ret = bt_audio_codec_cfg_set_frame_blocks_per_sdu(&preset.codec_cfg, frame_blocks);
169 zassert_true(ret > 0, "Unexpected return value %d", ret);
170
171 ret = bt_audio_codec_cfg_get_frame_blocks_per_sdu(&preset.codec_cfg, false);
172 zassert_equal(ret, frame_blocks, "Unexpected return value %d", ret);
173 }
174
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_set_freq)175 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_set_freq)
176 {
177 struct bt_bap_lc3_preset preset = BT_BAP_LC3_UNICAST_PRESET_16_2_1(
178 BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
179 int ret;
180
181 ret = bt_audio_codec_cfg_get_freq(&preset.codec_cfg);
182 zassert_equal(ret, 0x03, "Unexpected return value %d", ret);
183
184 ret = bt_audio_codec_cfg_set_freq(&preset.codec_cfg, BT_AUDIO_CODEC_CFG_FREQ_32KHZ);
185 zassert_true(ret > 0, "Unexpected return value %d", ret);
186
187 ret = bt_audio_codec_cfg_get_freq(&preset.codec_cfg);
188 zassert_equal(ret, 0x06, "Unexpected return value %d", ret);
189 }
190
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_frame_dur_to_frame_dur_us)191 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_frame_dur_to_frame_dur_us)
192 {
193 const struct frame_dur_test_input {
194 enum bt_audio_codec_cfg_frame_dur frame_dur;
195 uint32_t frame_dur_us;
196 } frame_dur_test_inputs[] = {
197 {.frame_dur = BT_AUDIO_CODEC_CFG_DURATION_7_5, .frame_dur_us = 7500U},
198 {.frame_dur = BT_AUDIO_CODEC_CFG_DURATION_10, .frame_dur_us = 10000U},
199 };
200
201 for (size_t i = 0U; i < ARRAY_SIZE(frame_dur_test_inputs); i++) {
202 const struct frame_dur_test_input *fdti = &frame_dur_test_inputs[i];
203
204 zassert_equal(bt_audio_codec_cfg_frame_dur_to_frame_dur_us(fdti->frame_dur),
205 fdti->frame_dur_us, "frame_dur %d was not coverted to %u",
206 fdti->frame_dur, fdti->frame_dur_us);
207 zassert_equal(bt_audio_codec_cfg_frame_dur_us_to_frame_dur(fdti->frame_dur_us),
208 fdti->frame_dur, "frame_dur_us %u was not coverted to %d",
209 fdti->frame_dur_us, fdti->frame_dur);
210 }
211 }
212
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_get_frame_dur)213 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_frame_dur)
214 {
215 const struct bt_bap_lc3_preset preset =
216 BT_BAP_LC3_UNICAST_PRESET_48_2_2(BT_AUDIO_LOCATION_FRONT_LEFT,
217 BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
218 int ret;
219
220 ret = bt_audio_codec_cfg_get_frame_dur(&preset.codec_cfg);
221 zassert_equal(ret, 0x01, "unexpected return value %d", ret);
222 }
223
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_set_frame_dur)224 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_set_frame_dur)
225 {
226 struct bt_bap_lc3_preset preset = BT_BAP_LC3_UNICAST_PRESET_16_2_1(
227 BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
228 int ret;
229
230 ret = bt_audio_codec_cfg_get_frame_dur(&preset.codec_cfg);
231 zassert_equal(ret, 0x01, "Unexpected return value %d", ret);
232
233 ret = bt_audio_codec_cfg_set_frame_dur(&preset.codec_cfg,
234 BT_AUDIO_CODEC_CFG_DURATION_7_5);
235 zassert_true(ret > 0, "Unexpected return value %d", ret);
236
237 ret = bt_audio_codec_cfg_get_frame_dur(&preset.codec_cfg);
238 zassert_equal(ret, 0x00, "Unexpected return value %d", ret);
239 }
240
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_get_chan_allocation)241 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_chan_allocation)
242 {
243 const struct bt_bap_lc3_preset preset = BT_BAP_LC3_UNICAST_PRESET_8_1_1(
244 BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
245 enum bt_audio_location chan_allocation = BT_AUDIO_LOCATION_FRONT_RIGHT;
246 int err;
247
248 err = bt_audio_codec_cfg_get_chan_allocation(&preset.codec_cfg, &chan_allocation, false);
249 zassert_false(err, "unexpected error %d", err);
250 zassert_equal(chan_allocation, BT_AUDIO_LOCATION_FRONT_LEFT, "unexpected return value %d",
251 chan_allocation);
252 }
253
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_get_chan_allocation_lc3_fallback_true)254 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_chan_allocation_lc3_fallback_true)
255 {
256 struct bt_audio_codec_cfg codec_cfg = {.id = BT_HCI_CODING_FORMAT_LC3};
257 enum bt_audio_location chan_allocation;
258 int err;
259
260 err = bt_audio_codec_cfg_get_chan_allocation(&codec_cfg, &chan_allocation, true);
261 zassert_equal(err, 0, "unexpected error %d", err);
262 zassert_equal(chan_allocation, BT_AUDIO_LOCATION_MONO_AUDIO, "unexpected return value %d",
263 chan_allocation);
264 }
265
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_get_chan_allocation_lc3_fallback_false)266 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_chan_allocation_lc3_fallback_false)
267 {
268 struct bt_audio_codec_cfg codec_cfg = {.id = BT_HCI_CODING_FORMAT_LC3};
269 enum bt_audio_location chan_allocation;
270 int err;
271
272 err = bt_audio_codec_cfg_get_chan_allocation(&codec_cfg, &chan_allocation, false);
273 zassert_equal(err, -ENODATA, "unexpected error %d", err);
274 }
275
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_get_chan_allocation_fallback_true)276 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_chan_allocation_fallback_true)
277 {
278 struct bt_audio_codec_cfg codec_cfg = {0};
279 enum bt_audio_location chan_allocation;
280 int err;
281
282 err = bt_audio_codec_cfg_get_chan_allocation(&codec_cfg, &chan_allocation, true);
283 zassert_equal(err, -ENODATA, "unexpected error %d", err);
284 }
285
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_get_chan_allocation_fallback_false)286 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_chan_allocation_fallback_false)
287 {
288 struct bt_audio_codec_cfg codec_cfg = {0};
289 enum bt_audio_location chan_allocation;
290 int err;
291
292 err = bt_audio_codec_cfg_get_chan_allocation(&codec_cfg, &chan_allocation, false);
293 zassert_equal(err, -ENODATA, "unexpected error %d", err);
294 }
295
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_set_chan_allocation)296 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_set_chan_allocation)
297 {
298 struct bt_bap_lc3_preset preset = BT_BAP_LC3_UNICAST_PRESET_16_2_1(
299 BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
300 enum bt_audio_location chan_allocation;
301 int err;
302
303 err = bt_audio_codec_cfg_get_chan_allocation(&preset.codec_cfg, &chan_allocation, false);
304 zassert_equal(err, 0, "Unexpected return value %d", err);
305 zassert_equal(chan_allocation, 0x00000001, "Unexpected chan_allocation value %d",
306 chan_allocation);
307
308 chan_allocation = BT_AUDIO_LOCATION_FRONT_RIGHT | BT_AUDIO_LOCATION_SIDE_RIGHT |
309 BT_AUDIO_LOCATION_TOP_SIDE_RIGHT | BT_AUDIO_LOCATION_RIGHT_SURROUND;
310 err = bt_audio_codec_cfg_set_chan_allocation(&preset.codec_cfg, chan_allocation);
311 zassert_true(err > 0, "Unexpected return value %d", err);
312
313 err = bt_audio_codec_cfg_get_chan_allocation(&preset.codec_cfg, &chan_allocation, false);
314 zassert_equal(err, 0, "Unexpected return value %d", err);
315 zassert_equal(chan_allocation, 0x8080802, "Unexpected chan_allocation value %d",
316 chan_allocation);
317 }
318
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_get_octets_per_frame)319 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_octets_per_frame)
320 {
321 const struct bt_bap_lc3_preset preset =
322 BT_BAP_LC3_UNICAST_PRESET_32_2_2(BT_AUDIO_LOCATION_FRONT_LEFT,
323 BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
324 int ret;
325
326 ret = bt_audio_codec_cfg_get_octets_per_frame(&preset.codec_cfg);
327 zassert_equal(ret, 80u, "unexpected return value %d", ret);
328 }
329
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_set_octets_per_frame)330 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_set_octets_per_frame)
331 {
332 struct bt_bap_lc3_preset preset = BT_BAP_LC3_UNICAST_PRESET_32_2_2(
333 BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
334 int ret;
335
336 ret = bt_audio_codec_cfg_get_octets_per_frame(&preset.codec_cfg);
337 zassert_equal(ret, 80, "Unexpected return value %d", ret);
338
339 ret = bt_audio_codec_cfg_set_octets_per_frame(&preset.codec_cfg, 120);
340 zassert_true(ret > 0, "Unexpected return value %d", ret);
341
342 ret = bt_audio_codec_cfg_get_octets_per_frame(&preset.codec_cfg);
343 zassert_equal(ret, 120, "Unexpected return value %d", ret);
344 }
345
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_get_frame_blocks_per_sdu)346 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_frame_blocks_per_sdu)
347 {
348 const struct bt_bap_lc3_preset preset =
349 BT_BAP_LC3_UNICAST_PRESET_48_5_1(BT_AUDIO_LOCATION_FRONT_LEFT,
350 BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
351 int ret;
352
353 ret = bt_audio_codec_cfg_get_frame_blocks_per_sdu(&preset.codec_cfg, true);
354 zassert_equal(ret, 1u, "unexpected return value %d", ret);
355 }
356
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_get_frame_blocks_per_sdu_lc3_fallback_true)357 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_frame_blocks_per_sdu_lc3_fallback_true)
358 {
359 struct bt_audio_codec_cfg codec_cfg = {.id = BT_HCI_CODING_FORMAT_LC3};
360 int err;
361
362 err = bt_audio_codec_cfg_get_frame_blocks_per_sdu(&codec_cfg, true);
363 zassert_equal(err, 1, "unexpected error %d", err);
364 }
365
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_get_frame_blocks_per_sdu_lc3_fallback_false)366 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_frame_blocks_per_sdu_lc3_fallback_false)
367 {
368 struct bt_audio_codec_cfg codec_cfg = {.id = BT_HCI_CODING_FORMAT_LC3};
369 int err;
370
371 err = bt_audio_codec_cfg_get_frame_blocks_per_sdu(&codec_cfg, false);
372 zassert_equal(err, -ENODATA, "unexpected error %d", err);
373 }
374
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_get_frame_blocks_per_sdu_fallback_true)375 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_frame_blocks_per_sdu_fallback_true)
376 {
377 struct bt_audio_codec_cfg codec_cfg = {0};
378 int err;
379
380 err = bt_audio_codec_cfg_get_frame_blocks_per_sdu(&codec_cfg, true);
381 zassert_equal(err, -ENODATA, "unexpected error %d", err);
382 }
383
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_get_frame_blocks_per_sdu_fallback_false)384 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_frame_blocks_per_sdu_fallback_false)
385 {
386 struct bt_audio_codec_cfg codec_cfg = {0};
387 int err;
388
389 err = bt_audio_codec_cfg_get_frame_blocks_per_sdu(&codec_cfg, false);
390 zassert_equal(err, -ENODATA, "unexpected error %d", err);
391 }
392
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_set_frame_blocks_per_sdu)393 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_set_frame_blocks_per_sdu)
394 {
395 struct bt_bap_lc3_preset preset = BT_BAP_LC3_UNICAST_PRESET_32_2_2(
396 BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
397 int ret;
398
399 ret = bt_audio_codec_cfg_get_frame_blocks_per_sdu(&preset.codec_cfg, true);
400 zassert_equal(ret, 1, "Unexpected return value %d", ret);
401
402 ret = bt_audio_codec_cfg_set_frame_blocks_per_sdu(&preset.codec_cfg, 2U);
403 zassert_true(ret > 0, "Unexpected return value %d", ret);
404
405 ret = bt_audio_codec_cfg_get_frame_blocks_per_sdu(&preset.codec_cfg, true);
406 zassert_equal(ret, 2, "Unexpected return value %d", ret);
407 }
408
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_val)409 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_val)
410 {
411 struct bt_audio_codec_cfg codec_cfg =
412 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
413 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
414 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)});
415 const uint8_t expected_data = BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE;
416 const uint8_t *data;
417 int ret;
418
419 ret = bt_audio_codec_cfg_meta_get_val(&codec_cfg, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
420 &data);
421 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
422 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
423 }
424
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_val)425 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_val)
426 {
427 struct bt_audio_codec_cfg codec_cfg =
428 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
429 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
430 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)});
431 const uint8_t new_expected_data = BT_AUDIO_PARENTAL_RATING_AGE_13_OR_ABOVE;
432 const uint8_t expected_data = BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE;
433 const uint8_t *data;
434 int ret;
435
436 ret = bt_audio_codec_cfg_meta_get_val(&codec_cfg, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
437 &data);
438 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
439 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
440
441 ret = bt_audio_codec_cfg_meta_set_val(&codec_cfg, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
442 &new_expected_data, sizeof(new_expected_data));
443 zassert_true(ret > 0, "Unexpected return value %d", ret);
444
445 ret = bt_audio_codec_cfg_meta_get_val(&codec_cfg, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
446 &data);
447 zassert_equal(ret, sizeof(new_expected_data), "Unexpected return value %d", ret);
448 zassert_equal(data[0], new_expected_data, "Unexpected data value %u", data[0]);
449 }
450
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_val_new)451 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_val_new)
452 {
453 struct bt_audio_codec_cfg codec_cfg =
454 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, {});
455 const uint8_t new_expected_data = BT_AUDIO_PARENTAL_RATING_AGE_13_OR_ABOVE;
456 const uint8_t *data;
457 int ret;
458
459 ret = bt_audio_codec_cfg_meta_get_val(&codec_cfg, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
460 &data);
461 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
462
463 ret = bt_audio_codec_cfg_meta_set_val(&codec_cfg, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
464 &new_expected_data, sizeof(new_expected_data));
465 zassert_true(ret > 0, "Unexpected return value %d", ret);
466
467 ret = bt_audio_codec_cfg_meta_get_val(&codec_cfg, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
468 &data);
469 zassert_equal(ret, sizeof(new_expected_data), "Unexpected return value %d", ret);
470 zassert_equal(data[0], new_expected_data, "Unexpected return value %d", ret);
471 }
472
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_unset_val)473 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_unset_val)
474 {
475 struct bt_audio_codec_cfg codec_cfg =
476 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
477 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
478 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)});
479 const uint8_t expected_data = BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE;
480 const uint8_t *data;
481 int ret;
482
483 ret = bt_audio_codec_cfg_meta_get_val(&codec_cfg, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
484 &data);
485 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
486 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
487
488 ret = bt_audio_codec_cfg_meta_unset_val(&codec_cfg, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING);
489 zassert_true(ret >= 0, "Unexpected return value %d", ret);
490
491 ret = bt_audio_codec_cfg_meta_get_val(&codec_cfg, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
492 &data);
493 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
494 }
495
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_pref_context)496 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_pref_context)
497 {
498 const enum bt_audio_context ctx =
499 BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | BT_AUDIO_CONTEXT_TYPE_MEDIA;
500 const struct bt_audio_codec_cfg codec_cfg =
501 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
502 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PREF_CONTEXT,
503 BT_BYTES_LIST_LE16(ctx))});
504 int ret;
505
506 ret = bt_audio_codec_cfg_meta_get_pref_context(&codec_cfg, false);
507 zassert_equal(ret, 0x0005, "unexpected return value %d", ret);
508 }
509
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_pref_context_lc3_fallback_true)510 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_pref_context_lc3_fallback_true)
511 {
512 struct bt_audio_codec_cfg codec_cfg = {.id = BT_HCI_CODING_FORMAT_LC3};
513 int err;
514
515 err = bt_audio_codec_cfg_meta_get_pref_context(&codec_cfg, true);
516 zassert_equal(err, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED, "unexpected error %d", err);
517 }
518
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_pref_context_lc3_fallback_false)519 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_pref_context_lc3_fallback_false)
520 {
521 struct bt_audio_codec_cfg codec_cfg = {.id = BT_HCI_CODING_FORMAT_LC3};
522 int err;
523
524 err = bt_audio_codec_cfg_meta_get_pref_context(&codec_cfg, false);
525 zassert_equal(err, -ENODATA, "unexpected error %d", err);
526 }
527
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_pref_context_fallback_true)528 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_pref_context_fallback_true)
529 {
530 struct bt_audio_codec_cfg codec_cfg = {0};
531 int err;
532
533 err = bt_audio_codec_cfg_meta_get_pref_context(&codec_cfg, true);
534 zassert_equal(err, -ENODATA, "unexpected error %d", err);
535 }
536
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_pref_context_fallback_false)537 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_pref_context_fallback_false)
538 {
539 struct bt_audio_codec_cfg codec_cfg = {0};
540 int err;
541
542 err = bt_audio_codec_cfg_meta_get_pref_context(&codec_cfg, true);
543 zassert_equal(err, -ENODATA, "unexpected error %d", err);
544 }
545
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_pref_context)546 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_pref_context)
547 {
548 const enum bt_audio_context ctx =
549 BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | BT_AUDIO_CONTEXT_TYPE_MEDIA;
550 const enum bt_audio_context new_ctx = BT_AUDIO_CONTEXT_TYPE_NOTIFICATIONS;
551 struct bt_audio_codec_cfg codec_cfg =
552 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
553 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PREF_CONTEXT,
554 BT_BYTES_LIST_LE16(ctx))});
555 int ret;
556
557 ret = bt_audio_codec_cfg_meta_get_pref_context(&codec_cfg, false);
558 zassert_equal(ret, 0x0005, "Unexpected return value %d", ret);
559
560 ret = bt_audio_codec_cfg_meta_set_pref_context(&codec_cfg, new_ctx);
561 zassert_true(ret > 0, "Unexpected return value %d", ret);
562
563 ret = bt_audio_codec_cfg_meta_get_pref_context(&codec_cfg, false);
564 zassert_equal(ret, 0x0100, "Unexpected return value %d", ret);
565 }
566
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_stream_context)567 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_stream_context)
568 {
569 const enum bt_audio_context ctx =
570 BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | BT_AUDIO_CONTEXT_TYPE_MEDIA;
571 const struct bt_audio_codec_cfg codec_cfg =
572 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
573 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT,
574 BT_BYTES_LIST_LE16(ctx))});
575 int ret;
576
577 ret = bt_audio_codec_cfg_meta_get_stream_context(&codec_cfg);
578 zassert_equal(ret, 0x0005, "unexpected return value %d", ret);
579 }
580
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_stream_context)581 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_stream_context)
582 {
583 enum bt_audio_context ctx = BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | BT_AUDIO_CONTEXT_TYPE_MEDIA;
584 struct bt_audio_codec_cfg codec_cfg =
585 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
586 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT,
587 BT_BYTES_LIST_LE16(ctx))});
588 int ret;
589
590 ret = bt_audio_codec_cfg_meta_get_stream_context(&codec_cfg);
591 zassert_equal(ret, 0x0005, "Unexpected return value %d", ret);
592
593 ctx = BT_AUDIO_CONTEXT_TYPE_NOTIFICATIONS;
594 ret = bt_audio_codec_cfg_meta_set_stream_context(&codec_cfg, ctx);
595 zassert_true(ret > 0, "Unexpected return value %d", ret);
596
597 ret = bt_audio_codec_cfg_meta_get_stream_context(&codec_cfg);
598 zassert_equal(ret, 0x0100, "Unexpected return value %d", ret);
599 }
600
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_program_info)601 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_program_info)
602 {
603 const uint8_t expected_data[] = {'P', 'r', 'o', 'g', 'r', 'a', 'm', ' ',
604 'I', 'n', 'f', 'o'};
605 const struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG(
606 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
607 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO,
608 'P', 'r', 'o', 'g', 'r', 'a', 'm', ' ',
609 'I', 'n', 'f', 'o')});
610 const uint8_t *program_data;
611 int ret;
612
613 ret = bt_audio_codec_cfg_meta_get_program_info(&codec_cfg, &program_data);
614 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
615 zassert_mem_equal(expected_data, program_data, ARRAY_SIZE(expected_data));
616 }
617
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_program_info)618 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_program_info)
619 {
620 const uint8_t expected_data[] = {'P', 'r', 'o', 'g', 'r', 'a',
621 'm', ' ', 'I', 'n', 'f', 'o'};
622 const uint8_t new_expected_data[] = {'N', 'e', 'w', ' ', 'i', 'n', 'f', 'o'};
623 struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG(
624 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
625 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO, 'P', 'r', 'o', 'g', 'r',
626 'a', 'm', ' ', 'I', 'n', 'f', 'o')});
627 const uint8_t *program_data;
628 int ret;
629
630 ret = bt_audio_codec_cfg_meta_get_program_info(&codec_cfg, &program_data);
631 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
632 zassert_mem_equal(expected_data, program_data, ARRAY_SIZE(expected_data));
633
634 ret = bt_audio_codec_cfg_meta_set_program_info(&codec_cfg, new_expected_data,
635 ARRAY_SIZE(new_expected_data));
636 zassert_true(ret > 0, "Unexpected return value %d", ret);
637
638 ret = bt_audio_codec_cfg_meta_get_program_info(&codec_cfg, &program_data);
639 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
640 zassert_mem_equal(new_expected_data, program_data, ARRAY_SIZE(new_expected_data));
641 }
642
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_lang)643 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_lang)
644 {
645 const struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG(
646 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
647 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_LANG, 'e', 'n', 'g')});
648 char expected_data[] = "eng";
649 const uint8_t *lang;
650 int ret;
651
652 ret = bt_audio_codec_cfg_meta_get_lang(&codec_cfg, &lang);
653 zassert_equal(ret, 0, "Unexpected return value %d", ret);
654 zassert_mem_equal(expected_data, lang, BT_AUDIO_LANG_SIZE);
655 }
656
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_lang)657 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_lang)
658 {
659 struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG(
660 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
661 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_LANG, 'e', 'n', 'g')});
662 const uint8_t new_expected_data[] = "deu";
663 char expected_data[] = "eng";
664 const uint8_t *lang;
665 int ret;
666
667 ret = bt_audio_codec_cfg_meta_get_lang(&codec_cfg, &lang);
668 zassert_equal(ret, 0, "Unexpected return value %d", ret);
669 zassert_mem_equal(expected_data, lang, BT_AUDIO_LANG_SIZE);
670
671 ret = bt_audio_codec_cfg_meta_set_lang(&codec_cfg, new_expected_data);
672 zassert_true(ret > 0, "Unexpected return value %d", ret);
673
674 ret = bt_audio_codec_cfg_meta_get_lang(&codec_cfg, &lang);
675 zassert_equal(ret, 0, "Unexpected return value %d", ret);
676 zassert_mem_equal(new_expected_data, lang, BT_AUDIO_LANG_SIZE);
677 }
678
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_ccid_list)679 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_ccid_list)
680 {
681 const uint8_t expected_data[] = {0x05, 0x10, 0x15};
682 const struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG(
683 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
684 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_CCID_LIST, 0x05, 0x10, 0x15)});
685 const uint8_t *ccid_list;
686 int ret;
687
688 ret = bt_audio_codec_cfg_meta_get_ccid_list(&codec_cfg, &ccid_list);
689 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
690 zassert_mem_equal(expected_data, ccid_list, ARRAY_SIZE(expected_data));
691 }
692
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_ccid_list_shorter)693 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_ccid_list_shorter)
694 {
695 const uint8_t expected_data[] = {0x05, 0x10, 0x15};
696 const uint8_t new_expected_data[] = {0x25, 0x30};
697 struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG(
698 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
699 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_CCID_LIST, 0x05, 0x10, 0x15)});
700 const uint8_t *ccid_list;
701 int ret;
702
703 ret = bt_audio_codec_cfg_meta_get_ccid_list(&codec_cfg, &ccid_list);
704 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
705 zassert_mem_equal(expected_data, ccid_list, ARRAY_SIZE(expected_data));
706
707 ret = bt_audio_codec_cfg_meta_set_ccid_list(&codec_cfg, new_expected_data,
708 ARRAY_SIZE(new_expected_data));
709 zassert_true(ret > 0, "Unexpected return value %d", ret);
710
711 ret = bt_audio_codec_cfg_meta_get_ccid_list(&codec_cfg, &ccid_list);
712 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
713 zassert_mem_equal(new_expected_data, ccid_list, ARRAY_SIZE(new_expected_data));
714 }
715
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_ccid_list_longer)716 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_ccid_list_longer)
717 {
718 const uint8_t expected_data[] = {0x05, 0x10, 0x15};
719 const uint8_t new_expected_data[] = {0x25, 0x30, 0x35, 0x40};
720 struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG(
721 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
722 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_CCID_LIST, 0x05, 0x10, 0x15)});
723 const uint8_t *ccid_list;
724 int ret;
725
726 ret = bt_audio_codec_cfg_meta_get_ccid_list(&codec_cfg, &ccid_list);
727 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
728 zassert_mem_equal(expected_data, ccid_list, ARRAY_SIZE(expected_data));
729
730 ret = bt_audio_codec_cfg_meta_set_ccid_list(&codec_cfg, new_expected_data,
731 ARRAY_SIZE(new_expected_data));
732 zassert_true(ret > 0, "Unexpected return value %d", ret);
733
734 ret = bt_audio_codec_cfg_meta_get_ccid_list(&codec_cfg, &ccid_list);
735 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
736 zassert_mem_equal(new_expected_data, ccid_list, ARRAY_SIZE(new_expected_data));
737 }
738
739 /* Providing multiple BT_AUDIO_CODEC_DATA to BT_AUDIO_CODEC_CFG without packing it in a macro
740 * cause compile issue, so define a macro to denote 2 types of data for the ccid_list_first tests
741 */
742 #define DOUBLE_CFG_DATA \
743 { \
744 BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_CCID_LIST, 0x05, 0x10, 0x15), \
745 BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING, \
746 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE) \
747 }
748
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_ccid_list_first_shorter)749 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_ccid_list_first_shorter)
750 {
751 const uint8_t expected_data[] = {0x05, 0x10, 0x15};
752 const uint8_t new_expected_data[] = {0x25, 0x30};
753 struct bt_audio_codec_cfg codec_cfg =
754 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, DOUBLE_CFG_DATA);
755 const uint8_t *ccid_list;
756 int ret;
757
758 ret = bt_audio_codec_cfg_meta_get_ccid_list(&codec_cfg, &ccid_list);
759 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
760 zassert_mem_equal(expected_data, ccid_list, ARRAY_SIZE(expected_data));
761
762 ret = bt_audio_codec_cfg_meta_get_parental_rating(&codec_cfg);
763 zassert_equal(ret, 0x07, "Unexpected return value %d", ret);
764
765 ret = bt_audio_codec_cfg_meta_set_ccid_list(&codec_cfg, new_expected_data,
766 ARRAY_SIZE(new_expected_data));
767 zassert_true(ret > 0, "Unexpected return value %d", ret);
768
769 ret = bt_audio_codec_cfg_meta_get_ccid_list(&codec_cfg, &ccid_list);
770 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
771 zassert_mem_equal(new_expected_data, ccid_list, ARRAY_SIZE(new_expected_data));
772
773 ret = bt_audio_codec_cfg_meta_get_parental_rating(&codec_cfg);
774 zassert_equal(ret, 0x07, "Unexpected return value %d", ret);
775 }
776
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_ccid_list_first_longer)777 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_ccid_list_first_longer)
778 {
779 const uint8_t expected_data[] = {0x05, 0x10, 0x15};
780 const uint8_t new_expected_data[] = {0x25, 0x30, 0x35, 0x40};
781 struct bt_audio_codec_cfg codec_cfg =
782 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, DOUBLE_CFG_DATA);
783 const uint8_t *ccid_list;
784 int ret;
785
786 ret = bt_audio_codec_cfg_meta_get_ccid_list(&codec_cfg, &ccid_list);
787 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
788 zassert_mem_equal(expected_data, ccid_list, ARRAY_SIZE(expected_data));
789
790 ret = bt_audio_codec_cfg_meta_get_parental_rating(&codec_cfg);
791 zassert_equal(ret, 0x07, "Unexpected return value %d", ret);
792
793 ret = bt_audio_codec_cfg_meta_set_ccid_list(&codec_cfg, new_expected_data,
794 ARRAY_SIZE(new_expected_data));
795 zassert_true(ret > 0, "Unexpected return value %d", ret);
796
797 ret = bt_audio_codec_cfg_meta_get_ccid_list(&codec_cfg, &ccid_list);
798 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
799 zassert_mem_equal(new_expected_data, ccid_list, ARRAY_SIZE(new_expected_data));
800
801 ret = bt_audio_codec_cfg_meta_get_parental_rating(&codec_cfg);
802 zassert_equal(ret, 0x07, "Unexpected return value %d", ret);
803 }
804
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_parental_rating)805 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_parental_rating)
806 {
807 const struct bt_audio_codec_cfg codec_cfg =
808 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
809 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
810 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)});
811 int ret;
812
813 ret = bt_audio_codec_cfg_meta_get_parental_rating(&codec_cfg);
814 zassert_equal(ret, 0x07, "Unexpected return value %d", ret);
815 }
816
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_parental_rating)817 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_parental_rating)
818 {
819 struct bt_audio_codec_cfg codec_cfg =
820 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
821 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
822 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)});
823 int ret;
824
825 ret = bt_audio_codec_cfg_meta_get_parental_rating(&codec_cfg);
826 zassert_equal(ret, 0x07, "Unexpected return value %d", ret);
827
828 ret = bt_audio_codec_cfg_meta_set_parental_rating(&codec_cfg,
829 BT_AUDIO_PARENTAL_RATING_AGE_13_OR_ABOVE);
830 zassert_true(ret > 0, "Unexpected return value %d", ret);
831
832 ret = bt_audio_codec_cfg_meta_get_parental_rating(&codec_cfg);
833 zassert_equal(ret, 0x0a, "Unexpected return value %d", ret);
834 }
835
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_program_info_uri)836 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_program_info_uri)
837 {
838 const uint8_t expected_data[] = {'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm'};
839 const struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG(
840 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
841 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI,
842 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm')});
843 const uint8_t *program_info_uri;
844 int ret;
845
846 ret = bt_audio_codec_cfg_meta_get_program_info_uri(&codec_cfg, &program_info_uri);
847 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
848 zassert_mem_equal(expected_data, program_info_uri, ARRAY_SIZE(expected_data));
849 }
850
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_program_info_uri)851 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_program_info_uri)
852 {
853 const uint8_t expected_data[] = {'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm'};
854 const uint8_t new_expected_data[] = {'n', 'e', 'w', '.', 'c', 'o', 'm'};
855 struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG(
856 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
857 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI, 'e', 'x', 'a', 'm',
858 'p', 'l', 'e', '.', 'c', 'o', 'm')});
859 const uint8_t *program_info_uri;
860 int ret;
861
862 ret = bt_audio_codec_cfg_meta_get_program_info_uri(&codec_cfg, &program_info_uri);
863 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
864 zassert_mem_equal(expected_data, program_info_uri, ARRAY_SIZE(expected_data));
865
866 ret = bt_audio_codec_cfg_meta_set_program_info_uri(&codec_cfg, new_expected_data,
867 ARRAY_SIZE(new_expected_data));
868 zassert_true(ret > 0, "Unexpected return value %d", ret);
869
870 ret = bt_audio_codec_cfg_meta_get_program_info_uri(&codec_cfg, &program_info_uri);
871 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
872 zassert_mem_equal(new_expected_data, program_info_uri, ARRAY_SIZE(new_expected_data));
873 }
874
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_audio_active_state)875 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_audio_active_state)
876 {
877 const struct bt_audio_codec_cfg codec_cfg =
878 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
879 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_AUDIO_STATE,
880 BT_AUDIO_ACTIVE_STATE_ENABLED)});
881 int ret;
882
883 ret = bt_audio_codec_cfg_meta_get_audio_active_state(&codec_cfg);
884 zassert_equal(ret, 0x01, "Unexpected return value %d", ret);
885 }
886
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_audio_active_state)887 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_audio_active_state)
888 {
889 struct bt_audio_codec_cfg codec_cfg =
890 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
891 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_AUDIO_STATE,
892 BT_AUDIO_ACTIVE_STATE_ENABLED)});
893 int ret;
894
895 ret = bt_audio_codec_cfg_meta_get_audio_active_state(&codec_cfg);
896 zassert_equal(ret, 0x01, "Unexpected return value %d", ret);
897
898 ret = bt_audio_codec_cfg_meta_set_audio_active_state(&codec_cfg,
899 BT_AUDIO_ACTIVE_STATE_DISABLED);
900 zassert_true(ret > 0, "Unexpected return value %d", ret);
901
902 ret = bt_audio_codec_cfg_meta_get_audio_active_state(&codec_cfg);
903 zassert_equal(ret, 0x00, "Unexpected return value %d", ret);
904 }
905
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_bcast_audio_immediate_rend_flag)906 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_bcast_audio_immediate_rend_flag)
907 {
908 const struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG(
909 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
910 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE)});
911 int ret;
912
913 ret = bt_audio_codec_cfg_meta_get_bcast_audio_immediate_rend_flag(&codec_cfg);
914 zassert_equal(ret, 0, "Unexpected return value %d", ret);
915 }
916
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_bcast_audio_immediate_rend_flag)917 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_bcast_audio_immediate_rend_flag)
918 {
919 struct bt_audio_codec_cfg codec_cfg =
920 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, {});
921 int ret;
922
923 ret = bt_audio_codec_cfg_meta_get_bcast_audio_immediate_rend_flag(&codec_cfg);
924 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
925
926 ret = bt_audio_codec_cfg_meta_set_bcast_audio_immediate_rend_flag(&codec_cfg);
927 zassert_true(ret > 0, "Unexpected return value %d", ret);
928
929 ret = bt_audio_codec_cfg_meta_get_bcast_audio_immediate_rend_flag(&codec_cfg);
930 zassert_equal(ret, 0, "Unexpected return value %d", ret);
931 }
932
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_assisted_listening_stream)933 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_assisted_listening_stream)
934 {
935 const struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG(
936 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
937 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_ASSISTED_LISTENING_STREAM,
938 BT_AUDIO_ASSISTED_LISTENING_STREAM_UNSPECIFIED)});
939 int ret;
940
941 ret = bt_audio_codec_cfg_meta_get_assisted_listening_stream(&codec_cfg);
942 zassert_equal(ret, 0x00, "Unexpected return value %d", ret);
943 }
944
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_assisted_listening_stream)945 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_assisted_listening_stream)
946 {
947 struct bt_audio_codec_cfg codec_cfg =
948 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, {});
949 int ret;
950
951 ret = bt_audio_codec_cfg_meta_get_assisted_listening_stream(&codec_cfg);
952 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
953
954 ret = bt_audio_codec_cfg_meta_set_assisted_listening_stream(
955 &codec_cfg, BT_AUDIO_ASSISTED_LISTENING_STREAM_UNSPECIFIED);
956 zassert_true(ret > 0, "Unexpected return value %d", ret);
957
958 ret = bt_audio_codec_cfg_meta_get_assisted_listening_stream(&codec_cfg);
959 zassert_equal(ret, 0x00, "Unexpected return value %d", ret);
960 }
961
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_broadcast_name)962 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_broadcast_name)
963 {
964 const uint8_t expected_data[] = {'m', 'y', ' ', 'b', 'c', 'a', 's', 't'};
965 const struct bt_audio_codec_cfg codec_cfg =
966 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
967 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_BROADCAST_NAME, 'm',
968 'y', ' ', 'b', 'c', 'a', 's', 't')});
969 const uint8_t *broadcast_name;
970 int ret;
971
972 ret = bt_audio_codec_cfg_meta_get_broadcast_name(&codec_cfg, &broadcast_name);
973 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
974 zassert_mem_equal(expected_data, broadcast_name, ARRAY_SIZE(expected_data));
975 }
976
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_broadcast_name)977 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_broadcast_name)
978 {
979 const uint8_t expected_data[] = {'m', 'y', ' ', 'b', 'c', 'a', 's', 't'};
980 const uint8_t new_expected_data[] = {'n', 'e', 'w', ' ', 'b', 'c', 'a', 's', 't'};
981 struct bt_audio_codec_cfg codec_cfg =
982 BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
983 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_BROADCAST_NAME, 'm',
984 'y', ' ', 'b', 'c', 'a', 's', 't')});
985 const uint8_t *broadcast_name;
986 int ret;
987
988 ret = bt_audio_codec_cfg_meta_get_broadcast_name(&codec_cfg, &broadcast_name);
989 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
990 zassert_mem_equal(expected_data, broadcast_name, ARRAY_SIZE(expected_data));
991
992 ret = bt_audio_codec_cfg_meta_set_broadcast_name(&codec_cfg, new_expected_data,
993 ARRAY_SIZE(new_expected_data));
994 zassert_true(ret > 0, "Unexpected return value %d", ret);
995
996 ret = bt_audio_codec_cfg_meta_get_broadcast_name(&codec_cfg, &broadcast_name);
997 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
998 zassert_mem_equal(new_expected_data, broadcast_name, ARRAY_SIZE(new_expected_data));
999 }
1000
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_extended)1001 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_extended)
1002 {
1003 const uint8_t expected_data[] = {0x00, 0x01, 0x02, 0x03};
1004 const struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG(
1005 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1006 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_EXTENDED, 0x00, 0x01, 0x02, 0x03)});
1007 const uint8_t *extended_meta;
1008 int ret;
1009
1010 ret = bt_audio_codec_cfg_meta_get_extended(&codec_cfg, &extended_meta);
1011 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1012 zassert_mem_equal(expected_data, extended_meta, ARRAY_SIZE(expected_data));
1013 }
1014
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_extended)1015 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_extended)
1016 {
1017 const uint8_t expected_data[] = {0x00, 0x01, 0x02, 0x03};
1018 const uint8_t new_expected_data[] = {0x04, 0x05};
1019 struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG(
1020 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1021 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_EXTENDED, 0x00, 0x01, 0x02, 0x03)});
1022 const uint8_t *extended_meta;
1023 int ret;
1024
1025 ret = bt_audio_codec_cfg_meta_get_extended(&codec_cfg, &extended_meta);
1026 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1027 zassert_mem_equal(expected_data, extended_meta, ARRAY_SIZE(expected_data));
1028
1029 ret = bt_audio_codec_cfg_meta_set_extended(&codec_cfg, new_expected_data,
1030 ARRAY_SIZE(new_expected_data));
1031 zassert_true(ret > 0, "Unexpected return value %d", ret);
1032
1033 ret = bt_audio_codec_cfg_meta_get_extended(&codec_cfg, &extended_meta);
1034 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
1035 zassert_mem_equal(new_expected_data, extended_meta, ARRAY_SIZE(new_expected_data));
1036 }
1037
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_get_vendor)1038 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_vendor)
1039 {
1040 const uint8_t expected_data[] = {0x00, 0x01, 0x02, 0x03};
1041 const struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG(
1042 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1043 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_VENDOR, 0x00, 0x01, 0x02, 0x03)});
1044 const uint8_t *vendor_meta;
1045 int ret;
1046
1047 ret = bt_audio_codec_cfg_meta_get_vendor(&codec_cfg, &vendor_meta);
1048 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1049 zassert_mem_equal(expected_data, vendor_meta, ARRAY_SIZE(expected_data));
1050 }
1051
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cfg_meta_set_vendor)1052 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_vendor)
1053 {
1054 const uint8_t expected_data[] = {0x00, 0x01, 0x02, 0x03};
1055 const uint8_t new_expected_data[] = {0x04, 0x05, 0x06, 0x07, 0x08};
1056 struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG(
1057 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1058 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_VENDOR, 0x00, 0x01, 0x02, 0x03)});
1059 const uint8_t *extended_meta;
1060 int ret;
1061
1062 ret = bt_audio_codec_cfg_meta_get_vendor(&codec_cfg, &extended_meta);
1063 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1064 zassert_mem_equal(expected_data, extended_meta, ARRAY_SIZE(expected_data));
1065
1066 ret = bt_audio_codec_cfg_meta_set_vendor(&codec_cfg, new_expected_data,
1067 ARRAY_SIZE(new_expected_data));
1068 zassert_true(ret > 0, "Unexpected return value %d", ret);
1069
1070 ret = bt_audio_codec_cfg_meta_get_vendor(&codec_cfg, &extended_meta);
1071 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
1072 zassert_mem_equal(new_expected_data, extended_meta, ARRAY_SIZE(new_expected_data));
1073 }
1074
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_val)1075 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_val)
1076 {
1077 struct bt_audio_codec_cap codec_cap =
1078 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000,
1079 {BT_AUDIO_CODEC_DATA(BT_AUDIO_CODEC_CFG_FREQ,
1080 BT_AUDIO_CODEC_CFG_FREQ_16KHZ)},
1081 {});
1082 const uint8_t expected_data = BT_AUDIO_CODEC_CFG_FREQ_16KHZ;
1083 const uint8_t *data;
1084 int ret;
1085
1086 ret = bt_audio_codec_cap_get_val(&codec_cap, BT_AUDIO_CODEC_CAP_TYPE_FREQ, &data);
1087 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
1088 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
1089 }
1090
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_set_val)1091 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_set_val)
1092 {
1093 struct bt_audio_codec_cap codec_cap =
1094 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000,
1095 {BT_AUDIO_CODEC_DATA(BT_AUDIO_CODEC_CFG_FREQ,
1096 BT_AUDIO_CODEC_CFG_FREQ_16KHZ)},
1097 {});
1098 const uint8_t new_expected_data = BT_AUDIO_CODEC_CFG_FREQ_48KHZ;
1099 const uint8_t expected_data = BT_AUDIO_CODEC_CFG_FREQ_16KHZ;
1100 const uint8_t *data;
1101 int ret;
1102
1103 ret = bt_audio_codec_cap_get_val(&codec_cap, BT_AUDIO_CODEC_CAP_TYPE_FREQ, &data);
1104 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
1105 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
1106
1107 ret = bt_audio_codec_cap_set_val(&codec_cap, BT_AUDIO_CODEC_CAP_TYPE_FREQ,
1108 &new_expected_data, sizeof(new_expected_data));
1109 zassert_true(ret > 0, "Unexpected return value %d", ret);
1110
1111 ret = bt_audio_codec_cap_get_val(&codec_cap, BT_AUDIO_CODEC_CAP_TYPE_FREQ, &data);
1112 zassert_equal(ret, sizeof(new_expected_data), "Unexpected return value %d", ret);
1113 zassert_equal(data[0], new_expected_data, "Unexpected data value %u", data[0]);
1114 }
1115
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_set_val_new)1116 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_set_val_new)
1117 {
1118 struct bt_audio_codec_cap codec_cap =
1119 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, {});
1120 const uint8_t new_expected_data = BT_AUDIO_CODEC_CFG_FREQ_48KHZ;
1121 const uint8_t *data;
1122 int ret;
1123
1124 ret = bt_audio_codec_cap_get_val(&codec_cap, BT_AUDIO_CODEC_CAP_TYPE_FREQ, &data);
1125 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1126
1127 ret = bt_audio_codec_cap_set_val(&codec_cap, BT_AUDIO_CODEC_CAP_TYPE_FREQ,
1128 &new_expected_data, sizeof(new_expected_data));
1129 zassert_true(ret > 0, "Unexpected return value %d", ret);
1130
1131 ret = bt_audio_codec_cap_get_val(&codec_cap, BT_AUDIO_CODEC_CAP_TYPE_FREQ, &data);
1132 zassert_equal(ret, sizeof(new_expected_data), "Unexpected return value %d", ret);
1133 zassert_equal(data[0], new_expected_data, "Unexpected return value %d", ret);
1134 }
1135
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_unset_val)1136 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_unset_val)
1137 {
1138 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1139 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000,
1140 {BT_AUDIO_CODEC_DATA(BT_AUDIO_CODEC_CAP_TYPE_FREQ, BT_AUDIO_CODEC_CAP_FREQ_16KHZ)},
1141 {});
1142 const uint8_t expected_data = BT_AUDIO_CODEC_CAP_FREQ_16KHZ;
1143 const uint8_t *data;
1144 int ret;
1145
1146 ret = bt_audio_codec_cap_get_val(&codec_cap, BT_AUDIO_CODEC_CAP_TYPE_FREQ, &data);
1147 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
1148 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
1149
1150 ret = bt_audio_codec_cap_unset_val(&codec_cap, BT_AUDIO_CODEC_CAP_TYPE_FREQ);
1151 zassert_true(ret >= 0, "Unexpected return value %d", ret);
1152
1153 ret = bt_audio_codec_cap_get_val(&codec_cap, BT_AUDIO_CODEC_CAP_TYPE_FREQ, &data);
1154 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1155 }
1156
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_freq)1157 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_freq)
1158 {
1159 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1160 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1161 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1162 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1163
1164 int ret;
1165
1166 ret = bt_audio_codec_cap_get_freq(&codec_cap);
1167 zassert_equal(ret, 4, "Unexpected return value %d", ret);
1168 }
1169
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_set_freq)1170 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_set_freq)
1171 {
1172 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1173 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1174 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1175 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1176
1177 int ret;
1178
1179 ret = bt_audio_codec_cap_get_freq(&codec_cap);
1180 zassert_equal(ret, 4, "Unexpected return value %d", ret);
1181
1182 ret = bt_audio_codec_cap_set_freq(&codec_cap, BT_AUDIO_CODEC_CAP_FREQ_22KHZ);
1183 zassert_true(ret > 0, "Unexpected return value %d", ret);
1184
1185 ret = bt_audio_codec_cap_get_freq(&codec_cap);
1186 zassert_equal(ret, 8, "Unexpected return value %d", ret);
1187 }
1188
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_frame_dur)1189 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_frame_dur)
1190 {
1191 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1192 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1193 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1194 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1195
1196 int ret;
1197
1198 ret = bt_audio_codec_cap_get_frame_dur(&codec_cap);
1199 zassert_equal(ret, 2, "Unexpected return value %d", ret);
1200 }
1201
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_set_frame_dur)1202 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_set_frame_dur)
1203 {
1204 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1205 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1206 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1207 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1208
1209 int ret;
1210
1211 ret = bt_audio_codec_cap_get_frame_dur(&codec_cap);
1212 zassert_equal(ret, 2, "Unexpected return value %d", ret);
1213
1214 ret = bt_audio_codec_cap_set_frame_dur(&codec_cap, BT_AUDIO_CODEC_CAP_DURATION_7_5);
1215 zassert_true(ret > 0, "Unexpected return value %d", ret);
1216
1217 ret = bt_audio_codec_cap_get_frame_dur(&codec_cap);
1218 zassert_equal(ret, 1, "Unexpected return value %d", ret);
1219 }
1220
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_supported_audio_chan_counts)1221 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_supported_audio_chan_counts)
1222 {
1223 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1224 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1225 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(2), 40U, 120U, 2U,
1226 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1227
1228 int ret;
1229
1230 ret = bt_audio_codec_cap_get_supported_audio_chan_counts(&codec_cap, false);
1231 zassert_equal(ret, 2, "Unexpected return value %d", ret);
1232 }
1233
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_supported_audio_chan_counts_lc3_fallback_true)1234 ZTEST(audio_codec_test_suite,
1235 test_bt_audio_codec_cap_get_supported_audio_chan_counts_lc3_fallback_true)
1236 {
1237 struct bt_audio_codec_cap codec_cap = {.id = BT_HCI_CODING_FORMAT_LC3};
1238 int err;
1239
1240 err = bt_audio_codec_cap_get_supported_audio_chan_counts(&codec_cap, true);
1241 zassert_equal(err, 1, "unexpected error %d", err);
1242 }
1243
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_supported_audio_chan_counts_lc3_fallback_false)1244 ZTEST(audio_codec_test_suite,
1245 test_bt_audio_codec_cap_get_supported_audio_chan_counts_lc3_fallback_false)
1246 {
1247 struct bt_audio_codec_cap codec_cap = {.id = BT_HCI_CODING_FORMAT_LC3};
1248 int err;
1249
1250 err = bt_audio_codec_cap_get_supported_audio_chan_counts(&codec_cap, false);
1251 zassert_equal(err, -ENODATA, "unexpected error %d", err);
1252 }
1253
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_supported_audio_chan_counts_fallback_true)1254 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_supported_audio_chan_counts_fallback_true)
1255 {
1256 struct bt_audio_codec_cap codec_cap = {0};
1257 int err;
1258
1259 err = bt_audio_codec_cap_get_supported_audio_chan_counts(&codec_cap, true);
1260 zassert_equal(err, -ENODATA, "unexpected error %d", err);
1261 }
1262
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_supported_audio_chan_counts_fallback_false)1263 ZTEST(audio_codec_test_suite,
1264 test_bt_audio_codec_cap_get_supported_audio_chan_counts_fallback_false)
1265 {
1266 struct bt_audio_codec_cap codec_cap = {0};
1267 int err;
1268
1269 err = bt_audio_codec_cap_get_supported_audio_chan_counts(&codec_cap, true);
1270 zassert_equal(err, -ENODATA, "unexpected error %d", err);
1271 }
1272
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_set_supported_audio_chan_counts)1273 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_set_supported_audio_chan_counts)
1274 {
1275 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1276 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1277 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1278 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1279
1280 int ret;
1281
1282 ret = bt_audio_codec_cap_get_supported_audio_chan_counts(&codec_cap, false);
1283 zassert_equal(ret, 1, "Unexpected return value %d", ret);
1284
1285 ret = bt_audio_codec_cap_set_supported_audio_chan_counts(
1286 &codec_cap, BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(2));
1287 zassert_true(ret > 0, "Unexpected return value %d", ret);
1288
1289 ret = bt_audio_codec_cap_get_supported_audio_chan_counts(&codec_cap, false);
1290 zassert_equal(ret, 2, "Unexpected return value %d", ret);
1291 }
1292
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_octets_per_frame)1293 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_octets_per_frame)
1294 {
1295 struct bt_audio_codec_octets_per_codec_frame expected = {
1296 .min = 40U,
1297 .max = 120U,
1298 };
1299 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1300 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1301 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1302 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1303 struct bt_audio_codec_octets_per_codec_frame codec_frame;
1304
1305 int ret;
1306
1307 ret = bt_audio_codec_cap_get_octets_per_frame(&codec_cap, &codec_frame);
1308 zassert_equal(ret, 0, "Unexpected return value %d", ret);
1309 zassert_equal(codec_frame.min, expected.min, "Unexpected minimum value %d",
1310 codec_frame.min);
1311 zassert_equal(codec_frame.max, expected.max, "Unexpected maximum value %d",
1312 codec_frame.max);
1313 }
1314
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_set_octets_per_frame)1315 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_set_octets_per_frame)
1316 {
1317 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1318 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1319 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1320 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1321 struct bt_audio_codec_octets_per_codec_frame codec_frame;
1322 int ret;
1323
1324 ret = bt_audio_codec_cap_get_octets_per_frame(&codec_cap, &codec_frame);
1325 zassert_equal(ret, 0, "Unexpected return value %d", ret);
1326 zassert_equal(codec_frame.min, 40U, "Unexpected minimum value %d", codec_frame.min);
1327 zassert_equal(codec_frame.max, 120U, "Unexpected maximum value %d", codec_frame.max);
1328
1329 codec_frame.min = 50U;
1330 codec_frame.max = 100U;
1331 ret = bt_audio_codec_cap_set_octets_per_frame(&codec_cap, &codec_frame);
1332 zassert_true(ret > 0, "Unexpected return value %d", ret);
1333
1334 ret = bt_audio_codec_cap_get_octets_per_frame(&codec_cap, &codec_frame);
1335 zassert_equal(ret, 0, "Unexpected return value %d", ret);
1336 zassert_equal(codec_frame.min, 50U, "Unexpected minimum value %d", codec_frame.min);
1337 zassert_equal(codec_frame.max, 100U, "Unexpected maximum value %d", codec_frame.max);
1338 }
1339
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_max_codec_frames_per_sdu)1340 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_max_codec_frames_per_sdu)
1341 {
1342 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1343 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1344 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1345 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1346
1347 int ret;
1348
1349 ret = bt_audio_codec_cap_get_max_codec_frames_per_sdu(&codec_cap, false);
1350 zassert_equal(ret, 2, "Unexpected return value %d", ret);
1351 }
1352
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_max_codec_frames_per_sdu_lc3_fallback_true)1353 ZTEST(audio_codec_test_suite,
1354 test_bt_audio_codec_cap_get_max_codec_frames_per_sdu_lc3_fallback_true)
1355 {
1356 struct bt_audio_codec_cap codec_cap = {.id = BT_HCI_CODING_FORMAT_LC3};
1357 int err;
1358
1359 err = bt_audio_codec_cap_get_max_codec_frames_per_sdu(&codec_cap, true);
1360 zassert_equal(err, 1, "unexpected error %d", err);
1361 }
1362
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_max_codec_frames_per_sdu_lc3_fallback_false)1363 ZTEST(audio_codec_test_suite,
1364 test_bt_audio_codec_cap_get_max_codec_frames_per_sdu_lc3_fallback_false)
1365 {
1366 struct bt_audio_codec_cap codec_cap = {.id = BT_HCI_CODING_FORMAT_LC3};
1367 int err;
1368
1369 err = bt_audio_codec_cap_get_max_codec_frames_per_sdu(&codec_cap, false);
1370 zassert_equal(err, -ENODATA, "unexpected error %d", err);
1371 }
1372
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_max_codec_frames_per_sdu_fallback_true)1373 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_max_codec_frames_per_sdu_fallback_true)
1374 {
1375 struct bt_audio_codec_cap codec_cap = {0};
1376 int err;
1377
1378 err = bt_audio_codec_cap_get_max_codec_frames_per_sdu(&codec_cap, true);
1379 zassert_equal(err, -ENODATA, "unexpected error %d", err);
1380 }
1381
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_max_codec_frames_per_sdu_fallback_false)1382 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_max_codec_frames_per_sdu_fallback_false)
1383 {
1384 struct bt_audio_codec_cap codec_cap = {0};
1385 int err;
1386
1387 err = bt_audio_codec_cap_get_max_codec_frames_per_sdu(&codec_cap, true);
1388 zassert_equal(err, -ENODATA, "unexpected error %d", err);
1389 }
1390
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_set_max_codec_frames_per_sdu)1391 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_set_max_codec_frames_per_sdu)
1392 {
1393 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1394 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1395 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1396 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1397
1398 int ret;
1399
1400 ret = bt_audio_codec_cap_get_max_codec_frames_per_sdu(&codec_cap, false);
1401 zassert_equal(ret, 2, "Unexpected return value %d", ret);
1402
1403 ret = bt_audio_codec_cap_set_max_codec_frames_per_sdu(&codec_cap, 4U);
1404 zassert_true(ret > 0, "Unexpected return value %d", ret);
1405
1406 ret = bt_audio_codec_cap_get_max_codec_frames_per_sdu(&codec_cap, false);
1407 zassert_equal(ret, 4, "Unexpected return value %d", ret);
1408 }
1409
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_val)1410 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_val)
1411 {
1412 struct bt_audio_codec_cap codec_cap =
1413 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1414 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1415 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)});
1416 const uint8_t expected_data = BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE;
1417 const uint8_t *data;
1418 int ret;
1419
1420 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1421 &data);
1422 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
1423 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
1424 }
1425
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_val)1426 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_val)
1427 {
1428 struct bt_audio_codec_cap codec_cap =
1429 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1430 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1431 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)});
1432 const uint8_t new_expected_data = BT_AUDIO_PARENTAL_RATING_AGE_13_OR_ABOVE;
1433 const uint8_t expected_data = BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE;
1434 const uint8_t *data;
1435 int ret;
1436
1437 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1438 &data);
1439 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
1440 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
1441
1442 ret = bt_audio_codec_cap_meta_set_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1443 &new_expected_data, sizeof(new_expected_data));
1444 zassert_true(ret > 0, "Unexpected return value %d", ret);
1445
1446 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1447 &data);
1448 zassert_equal(ret, sizeof(new_expected_data), "Unexpected return value %d", ret);
1449 zassert_equal(data[0], new_expected_data, "Unexpected data value %u", data[0]);
1450 }
1451
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_val_new)1452 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_val_new)
1453 {
1454 struct bt_audio_codec_cap codec_cap =
1455 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, {});
1456 const uint8_t new_expected_data = BT_AUDIO_PARENTAL_RATING_AGE_13_OR_ABOVE;
1457 const uint8_t *data;
1458 int ret;
1459
1460 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1461 &data);
1462 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1463
1464 ret = bt_audio_codec_cap_meta_set_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1465 &new_expected_data, sizeof(new_expected_data));
1466 zassert_true(ret > 0, "Unexpected return value %d", ret);
1467
1468 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1469 &data);
1470 zassert_equal(ret, sizeof(new_expected_data), "Unexpected return value %d", ret);
1471 zassert_equal(data[0], new_expected_data, "Unexpected return value %d", ret);
1472 }
1473
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_unset_val_only)1474 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_unset_val_only)
1475 {
1476 struct bt_audio_codec_cap codec_cap =
1477 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1478 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1479 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)});
1480 const uint8_t expected_data = BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE;
1481 const uint8_t *data;
1482 int ret;
1483
1484 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1485 &data);
1486 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
1487 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
1488
1489 ret = bt_audio_codec_cap_meta_unset_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING);
1490 zassert_true(ret >= 0, "Unexpected return value %d", ret);
1491
1492 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1493 &data);
1494 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1495 }
1496
1497 /* Providing multiple BT_AUDIO_CODEC_DATA to BT_AUDIO_CODEC_CAP without packing it in a macro
1498 * cause compile issue, so define a macro to denote 3 types of metadata for the meta_unset tests
1499 */
1500 #define TRIPLE_META_DATA \
1501 { \
1502 BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING, \
1503 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE), \
1504 BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PREF_CONTEXT, \
1505 BT_BYTES_LIST_LE16(BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED)), \
1506 BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT, \
1507 BT_BYTES_LIST_LE16(BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED)) \
1508 }
1509
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_unset_val_first)1510 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_unset_val_first)
1511 {
1512 struct bt_audio_codec_cap codec_cap =
1513 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, TRIPLE_META_DATA);
1514 const uint8_t expected_data = BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE;
1515 const uint8_t *data;
1516 int ret;
1517
1518 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1519 &data);
1520 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
1521 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
1522
1523 ret = bt_audio_codec_cap_meta_unset_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING);
1524 zassert_true(ret >= 0, "Unexpected return value %d", ret);
1525
1526 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1527 &data);
1528 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1529 }
1530
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_unset_val_middle)1531 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_unset_val_middle)
1532 {
1533 struct bt_audio_codec_cap codec_cap =
1534 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, TRIPLE_META_DATA);
1535 const uint16_t expected_data = BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED;
1536 const uint8_t *data;
1537 int ret;
1538
1539 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PREF_CONTEXT,
1540 &data);
1541 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
1542 zassert_equal(sys_get_le16(data), expected_data, "Unexpected return value %d", ret);
1543
1544 ret = bt_audio_codec_cap_meta_unset_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PREF_CONTEXT);
1545 zassert_true(ret >= 0, "Unexpected return value %d", ret);
1546
1547 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PREF_CONTEXT,
1548 &data);
1549 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1550 }
1551
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_unset_val_last)1552 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_unset_val_last)
1553 {
1554 struct bt_audio_codec_cap codec_cap =
1555 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, TRIPLE_META_DATA);
1556 const uint16_t expected_data = BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED;
1557 const uint8_t *data;
1558 int ret;
1559
1560 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT,
1561 &data);
1562 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
1563 zassert_equal(sys_get_le16(data), expected_data, "Unexpected return value %d", ret);
1564
1565 ret = bt_audio_codec_cap_meta_unset_val(&codec_cap, BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT);
1566 zassert_true(ret >= 0, "Unexpected return value %d", ret);
1567
1568 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT,
1569 &data);
1570 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1571 }
1572
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_pref_context)1573 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_pref_context)
1574 {
1575 const enum bt_audio_context ctx =
1576 BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | BT_AUDIO_CONTEXT_TYPE_MEDIA;
1577 const struct bt_audio_codec_cap codec_cap =
1578 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1579 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PREF_CONTEXT,
1580 BT_BYTES_LIST_LE16(ctx))});
1581 int ret;
1582
1583 ret = bt_audio_codec_cap_meta_get_pref_context(&codec_cap);
1584 zassert_equal(ret, 0x0005, "unexpected return value %d", ret);
1585 }
1586
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_pref_context)1587 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_pref_context)
1588 {
1589 const enum bt_audio_context ctx =
1590 BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | BT_AUDIO_CONTEXT_TYPE_MEDIA;
1591 const enum bt_audio_context new_ctx = BT_AUDIO_CONTEXT_TYPE_NOTIFICATIONS;
1592 struct bt_audio_codec_cap codec_cap =
1593 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1594 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PREF_CONTEXT,
1595 BT_BYTES_LIST_LE16(ctx))});
1596 int ret;
1597
1598 ret = bt_audio_codec_cap_meta_get_pref_context(&codec_cap);
1599 zassert_equal(ret, 0x0005, "Unexpected return value %d", ret);
1600
1601 ret = bt_audio_codec_cap_meta_set_pref_context(&codec_cap, new_ctx);
1602 zassert_true(ret > 0, "Unexpected return value %d", ret);
1603
1604 ret = bt_audio_codec_cap_meta_get_pref_context(&codec_cap);
1605 zassert_equal(ret, 0x0100, "Unexpected return value %d", ret);
1606 }
1607
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_stream_context)1608 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_stream_context)
1609 {
1610 const enum bt_audio_context ctx =
1611 BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | BT_AUDIO_CONTEXT_TYPE_MEDIA;
1612 const struct bt_audio_codec_cap codec_cap =
1613 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1614 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT,
1615 BT_BYTES_LIST_LE16(ctx))});
1616 int ret;
1617
1618 ret = bt_audio_codec_cap_meta_get_stream_context(&codec_cap);
1619 zassert_equal(ret, 0x0005, "unexpected return value %d", ret);
1620 }
1621
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_stream_context)1622 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_stream_context)
1623 {
1624 enum bt_audio_context ctx = BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | BT_AUDIO_CONTEXT_TYPE_MEDIA;
1625 struct bt_audio_codec_cap codec_cap =
1626 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1627 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT,
1628 BT_BYTES_LIST_LE16(ctx))});
1629 int ret;
1630
1631 ret = bt_audio_codec_cap_meta_get_stream_context(&codec_cap);
1632 zassert_equal(ret, 0x0005, "Unexpected return value %d", ret);
1633
1634 ctx = BT_AUDIO_CONTEXT_TYPE_NOTIFICATIONS;
1635 ret = bt_audio_codec_cap_meta_set_stream_context(&codec_cap, ctx);
1636 zassert_true(ret > 0, "Unexpected return value %d", ret);
1637
1638 ret = bt_audio_codec_cap_meta_get_stream_context(&codec_cap);
1639 zassert_equal(ret, 0x0100, "Unexpected return value %d", ret);
1640 }
1641
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_program_info)1642 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_program_info)
1643 {
1644 const uint8_t expected_data[] = {'P', 'r', 'o', 'g', 'r', 'a', 'm', ' ',
1645 'I', 'n', 'f', 'o'};
1646 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1647 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1648 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO,
1649 'P', 'r', 'o', 'g', 'r', 'a', 'm', ' ',
1650 'I', 'n', 'f', 'o')});
1651 const uint8_t *program_data;
1652 int ret;
1653
1654 ret = bt_audio_codec_cap_meta_get_program_info(&codec_cap, &program_data);
1655 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1656 zassert_mem_equal(expected_data, program_data, ARRAY_SIZE(expected_data));
1657 }
1658
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_program_info)1659 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_program_info)
1660 {
1661 const uint8_t expected_data[] = {'P', 'r', 'o', 'g', 'r', 'a',
1662 'm', ' ', 'I', 'n', 'f', 'o'};
1663 const uint8_t new_expected_data[] = {'N', 'e', 'w', ' ', 'i', 'n', 'f', 'o'};
1664 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1665 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1666 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO, 'P', 'r', 'o', 'g', 'r',
1667 'a', 'm', ' ', 'I', 'n', 'f', 'o')});
1668 const uint8_t *program_data;
1669 int ret;
1670
1671 ret = bt_audio_codec_cap_meta_get_program_info(&codec_cap, &program_data);
1672 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1673 zassert_mem_equal(expected_data, program_data, ARRAY_SIZE(expected_data));
1674
1675 ret = bt_audio_codec_cap_meta_set_program_info(&codec_cap, new_expected_data,
1676 ARRAY_SIZE(new_expected_data));
1677 zassert_true(ret > 0, "Unexpected return value %d", ret);
1678
1679 ret = bt_audio_codec_cap_meta_get_program_info(&codec_cap, &program_data);
1680 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
1681 zassert_mem_equal(new_expected_data, program_data, ARRAY_SIZE(new_expected_data));
1682 }
1683
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_lang)1684 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_lang)
1685 {
1686 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1687 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1688 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_LANG, 'e', 'n', 'g')});
1689 char expected_data[] = "eng";
1690 const uint8_t *lang;
1691 int ret;
1692
1693 ret = bt_audio_codec_cap_meta_get_lang(&codec_cap, &lang);
1694 zassert_equal(ret, 0, "Unexpected return value %d", ret);
1695 zassert_mem_equal(expected_data, lang, BT_AUDIO_LANG_SIZE);
1696 }
1697
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_lang)1698 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_lang)
1699 {
1700 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1701 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1702 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_LANG, 'e', 'n', 'g')});
1703 const uint8_t new_expected_data[] = "deu";
1704 char expected_data[] = "eng";
1705 const uint8_t *lang;
1706 int ret;
1707
1708 ret = bt_audio_codec_cap_meta_get_lang(&codec_cap, &lang);
1709 zassert_equal(ret, 0, "Unexpected return value %d", ret);
1710 zassert_mem_equal(expected_data, lang, BT_AUDIO_LANG_SIZE);
1711
1712 ret = bt_audio_codec_cap_meta_set_lang(&codec_cap, new_expected_data);
1713 zassert_true(ret > 0, "Unexpected return value %d", ret);
1714
1715 ret = bt_audio_codec_cap_meta_get_lang(&codec_cap, &lang);
1716 zassert_equal(ret, 0, "Unexpected return value %d", ret);
1717 zassert_mem_equal(new_expected_data, lang, BT_AUDIO_LANG_SIZE);
1718 }
1719
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_ccid_list)1720 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_ccid_list)
1721 {
1722 const uint8_t expected_data[] = {0x05, 0x10, 0x15};
1723 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1724 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1725 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_CCID_LIST, 0x05, 0x10, 0x15)});
1726 const uint8_t *ccid_list;
1727 int ret;
1728
1729 ret = bt_audio_codec_cap_meta_get_ccid_list(&codec_cap, &ccid_list);
1730 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1731 zassert_mem_equal(expected_data, ccid_list, ARRAY_SIZE(expected_data));
1732 }
1733
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_ccid_list)1734 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_ccid_list)
1735 {
1736 const uint8_t expected_data[] = {0x05, 0x10, 0x15};
1737 const uint8_t new_expected_data[] = {0x25, 0x30};
1738 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1739 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1740 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_CCID_LIST, 0x05, 0x10, 0x15)});
1741 const uint8_t *ccid_list;
1742 int ret;
1743
1744 ret = bt_audio_codec_cap_meta_get_ccid_list(&codec_cap, &ccid_list);
1745 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1746 zassert_mem_equal(expected_data, ccid_list, ARRAY_SIZE(expected_data));
1747
1748 ret = bt_audio_codec_cap_meta_set_ccid_list(&codec_cap, new_expected_data,
1749 ARRAY_SIZE(new_expected_data));
1750 zassert_true(ret > 0, "Unexpected return value %d", ret);
1751
1752 ret = bt_audio_codec_cap_meta_get_ccid_list(&codec_cap, &ccid_list);
1753 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
1754 zassert_mem_equal(new_expected_data, ccid_list, ARRAY_SIZE(new_expected_data));
1755 }
1756
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_parental_rating)1757 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_parental_rating)
1758 {
1759 const struct bt_audio_codec_cap codec_cap =
1760 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1761 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1762 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)});
1763 int ret;
1764
1765 ret = bt_audio_codec_cap_meta_get_parental_rating(&codec_cap);
1766 zassert_equal(ret, 0x07, "Unexpected return value %d", ret);
1767 }
1768
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_parental_rating)1769 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_parental_rating)
1770 {
1771 struct bt_audio_codec_cap codec_cap =
1772 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1773 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1774 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)});
1775 int ret;
1776
1777 ret = bt_audio_codec_cap_meta_get_parental_rating(&codec_cap);
1778 zassert_equal(ret, 0x07, "Unexpected return value %d", ret);
1779
1780 ret = bt_audio_codec_cap_meta_set_parental_rating(&codec_cap,
1781 BT_AUDIO_PARENTAL_RATING_AGE_13_OR_ABOVE);
1782 zassert_true(ret > 0, "Unexpected return value %d", ret);
1783
1784 ret = bt_audio_codec_cap_meta_get_parental_rating(&codec_cap);
1785 zassert_equal(ret, 0x0a, "Unexpected return value %d", ret);
1786 }
1787
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_program_info_uri)1788 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_program_info_uri)
1789 {
1790 const uint8_t expected_data[] = {'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm'};
1791 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1792 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1793 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI,
1794 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm')});
1795 const uint8_t *program_info_uri;
1796 int ret;
1797
1798 ret = bt_audio_codec_cap_meta_get_program_info_uri(&codec_cap, &program_info_uri);
1799 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1800 zassert_mem_equal(expected_data, program_info_uri, ARRAY_SIZE(expected_data));
1801 }
1802
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_program_info_uri)1803 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_program_info_uri)
1804 {
1805 const uint8_t expected_data[] = {'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm'};
1806 const uint8_t new_expected_data[] = {'n', 'e', 'w', '.', 'c', 'o', 'm'};
1807 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1808 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1809 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI, 'e', 'x', 'a', 'm',
1810 'p', 'l', 'e', '.', 'c', 'o', 'm')});
1811 const uint8_t *program_info_uri;
1812 int ret;
1813
1814 ret = bt_audio_codec_cap_meta_get_program_info_uri(&codec_cap, &program_info_uri);
1815 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1816 zassert_mem_equal(expected_data, program_info_uri, ARRAY_SIZE(expected_data));
1817
1818 ret = bt_audio_codec_cap_meta_set_program_info_uri(&codec_cap, new_expected_data,
1819 ARRAY_SIZE(new_expected_data));
1820 zassert_true(ret > 0, "Unexpected return value %d", ret);
1821
1822 ret = bt_audio_codec_cap_meta_get_program_info_uri(&codec_cap, &program_info_uri);
1823 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
1824 zassert_mem_equal(new_expected_data, program_info_uri, ARRAY_SIZE(new_expected_data));
1825 }
1826
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_audio_active_state)1827 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_audio_active_state)
1828 {
1829 const struct bt_audio_codec_cap codec_cap =
1830 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1831 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_AUDIO_STATE,
1832 BT_AUDIO_ACTIVE_STATE_ENABLED)});
1833 int ret;
1834
1835 ret = bt_audio_codec_cap_meta_get_audio_active_state(&codec_cap);
1836 zassert_equal(ret, 0x01, "Unexpected return value %d", ret);
1837 }
1838
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_audio_active_state)1839 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_audio_active_state)
1840 {
1841 struct bt_audio_codec_cap codec_cap =
1842 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1843 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_AUDIO_STATE,
1844 BT_AUDIO_ACTIVE_STATE_ENABLED)});
1845 int ret;
1846
1847 ret = bt_audio_codec_cap_meta_get_audio_active_state(&codec_cap);
1848 zassert_equal(ret, 0x01, "Unexpected return value %d", ret);
1849
1850 ret = bt_audio_codec_cap_meta_set_audio_active_state(&codec_cap,
1851 BT_AUDIO_ACTIVE_STATE_DISABLED);
1852 zassert_true(ret > 0, "Unexpected return value %d", ret);
1853
1854 ret = bt_audio_codec_cap_meta_get_audio_active_state(&codec_cap);
1855 zassert_equal(ret, 0x00, "Unexpected return value %d", ret);
1856 }
1857
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag)1858 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag)
1859 {
1860 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1861 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1862 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE)});
1863 int ret;
1864
1865 ret = bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag(&codec_cap);
1866 zassert_equal(ret, 0, "Unexpected return value %d", ret);
1867 }
1868
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_bcast_audio_immediate_rend_flag)1869 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_bcast_audio_immediate_rend_flag)
1870 {
1871 struct bt_audio_codec_cap codec_cap =
1872 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, {});
1873 int ret;
1874
1875 ret = bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag(&codec_cap);
1876 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1877
1878 ret = bt_audio_codec_cap_meta_set_bcast_audio_immediate_rend_flag(&codec_cap);
1879 zassert_true(ret > 0, "Unexpected return value %d", ret);
1880
1881 ret = bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag(&codec_cap);
1882 zassert_equal(ret, 0, "Unexpected return value %d", ret);
1883 }
1884
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_assisted_listening_stream)1885 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_assisted_listening_stream)
1886 {
1887 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1888 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1889 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_ASSISTED_LISTENING_STREAM,
1890 BT_AUDIO_ASSISTED_LISTENING_STREAM_UNSPECIFIED)});
1891 int ret;
1892
1893 ret = bt_audio_codec_cap_meta_get_assisted_listening_stream(&codec_cap);
1894 zassert_equal(ret, 0x00, "Unexpected return value %d", ret);
1895 }
1896
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_assisted_listening_stream)1897 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_assisted_listening_stream)
1898 {
1899 struct bt_audio_codec_cap codec_cap =
1900 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, {});
1901 int ret;
1902
1903 ret = bt_audio_codec_cap_meta_get_assisted_listening_stream(&codec_cap);
1904 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1905
1906 ret = bt_audio_codec_cap_meta_set_assisted_listening_stream(
1907 &codec_cap, BT_AUDIO_ASSISTED_LISTENING_STREAM_UNSPECIFIED);
1908 zassert_true(ret > 0, "Unexpected return value %d", ret);
1909
1910 ret = bt_audio_codec_cap_meta_get_assisted_listening_stream(&codec_cap);
1911 zassert_equal(ret, 0x00, "Unexpected return value %d", ret);
1912 }
1913
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_broadcast_name)1914 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_broadcast_name)
1915 {
1916 const uint8_t expected_data[] = {'m', 'y', ' ', 'b', 'c', 'a', 's', 't'};
1917 const struct bt_audio_codec_cap codec_cap =
1918 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1919 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_BROADCAST_NAME, 'm',
1920 'y', ' ', 'b', 'c', 'a', 's', 't')});
1921 const uint8_t *broadcast_name;
1922 int ret;
1923
1924 ret = bt_audio_codec_cap_meta_get_broadcast_name(&codec_cap, &broadcast_name);
1925 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1926 zassert_mem_equal(expected_data, broadcast_name, ARRAY_SIZE(expected_data));
1927 }
1928
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_broadcast_name)1929 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_broadcast_name)
1930 {
1931 const uint8_t expected_data[] = {'m', 'y', ' ', 'b', 'c', 'a', 's', 't'};
1932 const uint8_t new_expected_data[] = {'n', 'e', 'w', ' ', 'b', 'c', 'a', 's', 't'};
1933 struct bt_audio_codec_cap codec_cap =
1934 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1935 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_BROADCAST_NAME, 'm',
1936 'y', ' ', 'b', 'c', 'a', 's', 't')});
1937 const uint8_t *broadcast_name;
1938 int ret;
1939
1940 ret = bt_audio_codec_cap_meta_get_broadcast_name(&codec_cap, &broadcast_name);
1941 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1942 zassert_mem_equal(expected_data, broadcast_name, ARRAY_SIZE(expected_data));
1943
1944 ret = bt_audio_codec_cap_meta_set_broadcast_name(&codec_cap, new_expected_data,
1945 ARRAY_SIZE(new_expected_data));
1946 zassert_true(ret > 0, "Unexpected return value %d", ret);
1947
1948 ret = bt_audio_codec_cap_meta_get_broadcast_name(&codec_cap, &broadcast_name);
1949 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
1950 zassert_mem_equal(new_expected_data, broadcast_name, ARRAY_SIZE(new_expected_data));
1951 }
1952
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_extended)1953 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_extended)
1954 {
1955 const uint8_t expected_data[] = {0x00, 0x01, 0x02, 0x03};
1956 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1957 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1958 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_EXTENDED, 0x00, 0x01, 0x02, 0x03)});
1959 const uint8_t *extended_meta;
1960 int ret;
1961
1962 ret = bt_audio_codec_cap_meta_get_extended(&codec_cap, &extended_meta);
1963 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1964 zassert_mem_equal(expected_data, extended_meta, ARRAY_SIZE(expected_data));
1965 }
1966
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_extended)1967 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_extended)
1968 {
1969 const uint8_t expected_data[] = {0x00, 0x01, 0x02, 0x03};
1970 const uint8_t new_expected_data[] = {0x04, 0x05};
1971 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1972 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1973 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_EXTENDED, 0x00, 0x01, 0x02, 0x03)});
1974 const uint8_t *extended_meta;
1975 int ret;
1976
1977 ret = bt_audio_codec_cap_meta_get_extended(&codec_cap, &extended_meta);
1978 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1979 zassert_mem_equal(expected_data, extended_meta, ARRAY_SIZE(expected_data));
1980
1981 ret = bt_audio_codec_cap_meta_set_extended(&codec_cap, new_expected_data,
1982 ARRAY_SIZE(new_expected_data));
1983 zassert_true(ret > 0, "Unexpected return value %d", ret);
1984
1985 ret = bt_audio_codec_cap_meta_get_extended(&codec_cap, &extended_meta);
1986 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
1987 zassert_mem_equal(new_expected_data, extended_meta, ARRAY_SIZE(new_expected_data));
1988 }
1989
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_vendor)1990 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_vendor)
1991 {
1992 const uint8_t expected_data[] = {0x00, 0x01, 0x02, 0x03};
1993 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1994 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1995 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_VENDOR, 0x00, 0x01, 0x02, 0x03)});
1996 const uint8_t *vendor_meta;
1997 int ret;
1998
1999 ret = bt_audio_codec_cap_meta_get_vendor(&codec_cap, &vendor_meta);
2000 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
2001 zassert_mem_equal(expected_data, vendor_meta, ARRAY_SIZE(expected_data));
2002 }
2003
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_vendor)2004 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_vendor)
2005 {
2006 const uint8_t expected_data[] = {0x00, 0x01, 0x02, 0x03};
2007 const uint8_t new_expected_data[] = {0x04, 0x05, 0x06, 0x07, 0x08};
2008 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
2009 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
2010 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_VENDOR, 0x00, 0x01, 0x02, 0x03)});
2011 const uint8_t *extended_meta;
2012 int ret;
2013
2014 ret = bt_audio_codec_cap_meta_get_vendor(&codec_cap, &extended_meta);
2015 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
2016 zassert_mem_equal(expected_data, extended_meta, ARRAY_SIZE(expected_data));
2017
2018 ret = bt_audio_codec_cap_meta_set_vendor(&codec_cap, new_expected_data,
2019 ARRAY_SIZE(new_expected_data));
2020 zassert_true(ret > 0, "Unexpected return value %d", ret);
2021
2022 ret = bt_audio_codec_cap_meta_get_vendor(&codec_cap, &extended_meta);
2023 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
2024 zassert_mem_equal(new_expected_data, extended_meta, ARRAY_SIZE(new_expected_data));
2025 }
2026