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 =
1139 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000,
1140 {BT_AUDIO_CODEC_DATA(BT_AUDIO_CODEC_CFG_FREQ,
1141 BT_AUDIO_CODEC_CFG_FREQ_16KHZ)},
1142 {});
1143 const uint8_t expected_data = BT_AUDIO_CODEC_CFG_FREQ_16KHZ;
1144 const uint8_t *data;
1145 int ret;
1146
1147 ret = bt_audio_codec_cap_get_val(&codec_cap, BT_AUDIO_CODEC_CFG_FREQ, &data);
1148 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
1149 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
1150
1151 ret = bt_audio_codec_cap_unset_val(&codec_cap, BT_AUDIO_CODEC_CFG_FREQ);
1152 zassert_true(ret >= 0, "Unexpected return value %d", ret);
1153
1154 ret = bt_audio_codec_cap_get_val(&codec_cap, BT_AUDIO_CODEC_CFG_FREQ, &data);
1155 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1156 }
1157
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_freq)1158 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_freq)
1159 {
1160 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1161 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1162 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1163 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1164
1165 int ret;
1166
1167 ret = bt_audio_codec_cap_get_freq(&codec_cap);
1168 zassert_equal(ret, 4, "Unexpected return value %d", ret);
1169 }
1170
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_set_freq)1171 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_set_freq)
1172 {
1173 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1174 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1175 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1176 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1177
1178 int ret;
1179
1180 ret = bt_audio_codec_cap_get_freq(&codec_cap);
1181 zassert_equal(ret, 4, "Unexpected return value %d", ret);
1182
1183 ret = bt_audio_codec_cap_set_freq(&codec_cap, BT_AUDIO_CODEC_CAP_FREQ_22KHZ);
1184 zassert_true(ret > 0, "Unexpected return value %d", ret);
1185
1186 ret = bt_audio_codec_cap_get_freq(&codec_cap);
1187 zassert_equal(ret, 8, "Unexpected return value %d", ret);
1188 }
1189
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_frame_dur)1190 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_frame_dur)
1191 {
1192 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1193 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1194 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1195 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1196
1197 int ret;
1198
1199 ret = bt_audio_codec_cap_get_frame_dur(&codec_cap);
1200 zassert_equal(ret, 2, "Unexpected return value %d", ret);
1201 }
1202
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_set_frame_dur)1203 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_set_frame_dur)
1204 {
1205 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1206 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1207 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1208 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1209
1210 int ret;
1211
1212 ret = bt_audio_codec_cap_get_frame_dur(&codec_cap);
1213 zassert_equal(ret, 2, "Unexpected return value %d", ret);
1214
1215 ret = bt_audio_codec_cap_set_frame_dur(&codec_cap, BT_AUDIO_CODEC_CAP_DURATION_7_5);
1216 zassert_true(ret > 0, "Unexpected return value %d", ret);
1217
1218 ret = bt_audio_codec_cap_get_frame_dur(&codec_cap);
1219 zassert_equal(ret, 1, "Unexpected return value %d", ret);
1220 }
1221
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_supported_audio_chan_counts)1222 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_supported_audio_chan_counts)
1223 {
1224 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1225 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1226 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(2), 40U, 120U, 2U,
1227 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1228
1229 int ret;
1230
1231 ret = bt_audio_codec_cap_get_supported_audio_chan_counts(&codec_cap, false);
1232 zassert_equal(ret, 2, "Unexpected return value %d", ret);
1233 }
1234
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_supported_audio_chan_counts_lc3_fallback_true)1235 ZTEST(audio_codec_test_suite,
1236 test_bt_audio_codec_cap_get_supported_audio_chan_counts_lc3_fallback_true)
1237 {
1238 struct bt_audio_codec_cap codec_cap = {.id = BT_HCI_CODING_FORMAT_LC3};
1239 int err;
1240
1241 err = bt_audio_codec_cap_get_supported_audio_chan_counts(&codec_cap, true);
1242 zassert_equal(err, 1, "unexpected error %d", err);
1243 }
1244
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_supported_audio_chan_counts_lc3_fallback_false)1245 ZTEST(audio_codec_test_suite,
1246 test_bt_audio_codec_cap_get_supported_audio_chan_counts_lc3_fallback_false)
1247 {
1248 struct bt_audio_codec_cap codec_cap = {.id = BT_HCI_CODING_FORMAT_LC3};
1249 int err;
1250
1251 err = bt_audio_codec_cap_get_supported_audio_chan_counts(&codec_cap, false);
1252 zassert_equal(err, -ENODATA, "unexpected error %d", err);
1253 }
1254
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_supported_audio_chan_counts_fallback_true)1255 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_supported_audio_chan_counts_fallback_true)
1256 {
1257 struct bt_audio_codec_cap codec_cap = {0};
1258 int err;
1259
1260 err = bt_audio_codec_cap_get_supported_audio_chan_counts(&codec_cap, true);
1261 zassert_equal(err, -ENODATA, "unexpected error %d", err);
1262 }
1263
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_supported_audio_chan_counts_fallback_false)1264 ZTEST(audio_codec_test_suite,
1265 test_bt_audio_codec_cap_get_supported_audio_chan_counts_fallback_false)
1266 {
1267 struct bt_audio_codec_cap codec_cap = {0};
1268 int err;
1269
1270 err = bt_audio_codec_cap_get_supported_audio_chan_counts(&codec_cap, true);
1271 zassert_equal(err, -ENODATA, "unexpected error %d", err);
1272 }
1273
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_set_supported_audio_chan_counts)1274 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_set_supported_audio_chan_counts)
1275 {
1276 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1277 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1278 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1279 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1280
1281 int ret;
1282
1283 ret = bt_audio_codec_cap_get_supported_audio_chan_counts(&codec_cap, false);
1284 zassert_equal(ret, 1, "Unexpected return value %d", ret);
1285
1286 ret = bt_audio_codec_cap_set_supported_audio_chan_counts(
1287 &codec_cap, BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(2));
1288 zassert_true(ret > 0, "Unexpected return value %d", ret);
1289
1290 ret = bt_audio_codec_cap_get_supported_audio_chan_counts(&codec_cap, false);
1291 zassert_equal(ret, 2, "Unexpected return value %d", ret);
1292 }
1293
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_octets_per_frame)1294 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_octets_per_frame)
1295 {
1296 struct bt_audio_codec_octets_per_codec_frame expected = {
1297 .min = 40U,
1298 .max = 120U,
1299 };
1300 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1301 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1302 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1303 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1304 struct bt_audio_codec_octets_per_codec_frame codec_frame;
1305
1306 int ret;
1307
1308 ret = bt_audio_codec_cap_get_octets_per_frame(&codec_cap, &codec_frame);
1309 zassert_equal(ret, 0, "Unexpected return value %d", ret);
1310 zassert_equal(codec_frame.min, expected.min, "Unexpected minimum value %d",
1311 codec_frame.min);
1312 zassert_equal(codec_frame.max, expected.max, "Unexpected maximum value %d",
1313 codec_frame.max);
1314 }
1315
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_set_octets_per_frame)1316 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_set_octets_per_frame)
1317 {
1318 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1319 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1320 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1321 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1322 struct bt_audio_codec_octets_per_codec_frame codec_frame;
1323 int ret;
1324
1325 ret = bt_audio_codec_cap_get_octets_per_frame(&codec_cap, &codec_frame);
1326 zassert_equal(ret, 0, "Unexpected return value %d", ret);
1327 zassert_equal(codec_frame.min, 40U, "Unexpected minimum value %d", codec_frame.min);
1328 zassert_equal(codec_frame.max, 120U, "Unexpected maximum value %d", codec_frame.max);
1329
1330 codec_frame.min = 50U;
1331 codec_frame.max = 100U;
1332 ret = bt_audio_codec_cap_set_octets_per_frame(&codec_cap, &codec_frame);
1333 zassert_true(ret > 0, "Unexpected return value %d", ret);
1334
1335 ret = bt_audio_codec_cap_get_octets_per_frame(&codec_cap, &codec_frame);
1336 zassert_equal(ret, 0, "Unexpected return value %d", ret);
1337 zassert_equal(codec_frame.min, 50U, "Unexpected minimum value %d", codec_frame.min);
1338 zassert_equal(codec_frame.max, 100U, "Unexpected maximum value %d", codec_frame.max);
1339 }
1340
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_max_codec_frames_per_sdu)1341 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_max_codec_frames_per_sdu)
1342 {
1343 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1344 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1345 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1346 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1347
1348 int ret;
1349
1350 ret = bt_audio_codec_cap_get_max_codec_frames_per_sdu(&codec_cap, false);
1351 zassert_equal(ret, 2, "Unexpected return value %d", ret);
1352 }
1353
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_max_codec_frames_per_sdu_lc3_fallback_true)1354 ZTEST(audio_codec_test_suite,
1355 test_bt_audio_codec_cap_get_max_codec_frames_per_sdu_lc3_fallback_true)
1356 {
1357 struct bt_audio_codec_cap codec_cap = {.id = BT_HCI_CODING_FORMAT_LC3};
1358 int err;
1359
1360 err = bt_audio_codec_cap_get_max_codec_frames_per_sdu(&codec_cap, true);
1361 zassert_equal(err, 1, "unexpected error %d", err);
1362 }
1363
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_max_codec_frames_per_sdu_lc3_fallback_false)1364 ZTEST(audio_codec_test_suite,
1365 test_bt_audio_codec_cap_get_max_codec_frames_per_sdu_lc3_fallback_false)
1366 {
1367 struct bt_audio_codec_cap codec_cap = {.id = BT_HCI_CODING_FORMAT_LC3};
1368 int err;
1369
1370 err = bt_audio_codec_cap_get_max_codec_frames_per_sdu(&codec_cap, false);
1371 zassert_equal(err, -ENODATA, "unexpected error %d", err);
1372 }
1373
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_max_codec_frames_per_sdu_fallback_true)1374 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_max_codec_frames_per_sdu_fallback_true)
1375 {
1376 struct bt_audio_codec_cap codec_cap = {0};
1377 int err;
1378
1379 err = bt_audio_codec_cap_get_max_codec_frames_per_sdu(&codec_cap, true);
1380 zassert_equal(err, -ENODATA, "unexpected error %d", err);
1381 }
1382
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_get_max_codec_frames_per_sdu_fallback_false)1383 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_get_max_codec_frames_per_sdu_fallback_false)
1384 {
1385 struct bt_audio_codec_cap codec_cap = {0};
1386 int err;
1387
1388 err = bt_audio_codec_cap_get_max_codec_frames_per_sdu(&codec_cap, true);
1389 zassert_equal(err, -ENODATA, "unexpected error %d", err);
1390 }
1391
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_set_max_codec_frames_per_sdu)1392 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_set_max_codec_frames_per_sdu)
1393 {
1394 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
1395 BT_AUDIO_CODEC_CAP_FREQ_16KHZ, BT_AUDIO_CODEC_CAP_DURATION_10,
1396 BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1), 40U, 120U, 2U,
1397 (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA));
1398
1399 int ret;
1400
1401 ret = bt_audio_codec_cap_get_max_codec_frames_per_sdu(&codec_cap, false);
1402 zassert_equal(ret, 2, "Unexpected return value %d", ret);
1403
1404 ret = bt_audio_codec_cap_set_max_codec_frames_per_sdu(&codec_cap, 4U);
1405 zassert_true(ret > 0, "Unexpected return value %d", ret);
1406
1407 ret = bt_audio_codec_cap_get_max_codec_frames_per_sdu(&codec_cap, false);
1408 zassert_equal(ret, 4, "Unexpected return value %d", ret);
1409 }
1410
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_val)1411 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_val)
1412 {
1413 struct bt_audio_codec_cap codec_cap =
1414 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1415 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1416 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)});
1417 const uint8_t expected_data = BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE;
1418 const uint8_t *data;
1419 int ret;
1420
1421 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1422 &data);
1423 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
1424 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
1425 }
1426
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_val)1427 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_val)
1428 {
1429 struct bt_audio_codec_cap codec_cap =
1430 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1431 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1432 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)});
1433 const uint8_t new_expected_data = BT_AUDIO_PARENTAL_RATING_AGE_13_OR_ABOVE;
1434 const uint8_t expected_data = BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE;
1435 const uint8_t *data;
1436 int ret;
1437
1438 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1439 &data);
1440 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
1441 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
1442
1443 ret = bt_audio_codec_cap_meta_set_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1444 &new_expected_data, sizeof(new_expected_data));
1445 zassert_true(ret > 0, "Unexpected return value %d", ret);
1446
1447 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1448 &data);
1449 zassert_equal(ret, sizeof(new_expected_data), "Unexpected return value %d", ret);
1450 zassert_equal(data[0], new_expected_data, "Unexpected data value %u", data[0]);
1451 }
1452
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_val_new)1453 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_val_new)
1454 {
1455 struct bt_audio_codec_cap codec_cap =
1456 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, {});
1457 const uint8_t new_expected_data = BT_AUDIO_PARENTAL_RATING_AGE_13_OR_ABOVE;
1458 const uint8_t *data;
1459 int ret;
1460
1461 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1462 &data);
1463 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1464
1465 ret = bt_audio_codec_cap_meta_set_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1466 &new_expected_data, sizeof(new_expected_data));
1467 zassert_true(ret > 0, "Unexpected return value %d", ret);
1468
1469 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1470 &data);
1471 zassert_equal(ret, sizeof(new_expected_data), "Unexpected return value %d", ret);
1472 zassert_equal(data[0], new_expected_data, "Unexpected return value %d", ret);
1473 }
1474
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_unset_val_only)1475 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_unset_val_only)
1476 {
1477 struct bt_audio_codec_cap codec_cap =
1478 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1479 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1480 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)});
1481 const uint8_t expected_data = BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE;
1482 const uint8_t *data;
1483 int ret;
1484
1485 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1486 &data);
1487 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
1488 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
1489
1490 ret = bt_audio_codec_cap_meta_unset_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING);
1491 zassert_true(ret >= 0, "Unexpected return value %d", ret);
1492
1493 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1494 &data);
1495 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1496 }
1497
1498 /* Providing multiple BT_AUDIO_CODEC_DATA to BT_AUDIO_CODEC_CAP without packing it in a macro
1499 * cause compile issue, so define a macro to denote 3 types of metadata for the meta_unset tests
1500 */
1501 #define TRIPLE_META_DATA \
1502 { \
1503 BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING, \
1504 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE), \
1505 BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PREF_CONTEXT, \
1506 BT_BYTES_LIST_LE16(BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED)), \
1507 BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT, \
1508 BT_BYTES_LIST_LE16(BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED)) \
1509 }
1510
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_unset_val_first)1511 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_unset_val_first)
1512 {
1513 struct bt_audio_codec_cap codec_cap =
1514 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, TRIPLE_META_DATA);
1515 const uint8_t expected_data = BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE;
1516 const uint8_t *data;
1517 int ret;
1518
1519 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1520 &data);
1521 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
1522 zassert_equal(data[0], expected_data, "Unexpected return value %d", ret);
1523
1524 ret = bt_audio_codec_cap_meta_unset_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING);
1525 zassert_true(ret >= 0, "Unexpected return value %d", ret);
1526
1527 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1528 &data);
1529 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1530 }
1531
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_unset_val_middle)1532 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_unset_val_middle)
1533 {
1534 struct bt_audio_codec_cap codec_cap =
1535 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, TRIPLE_META_DATA);
1536 const uint16_t expected_data = BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED;
1537 const uint8_t *data;
1538 int ret;
1539
1540 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PREF_CONTEXT,
1541 &data);
1542 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
1543 zassert_equal(sys_get_le16(data), expected_data, "Unexpected return value %d", ret);
1544
1545 ret = bt_audio_codec_cap_meta_unset_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PREF_CONTEXT);
1546 zassert_true(ret >= 0, "Unexpected return value %d", ret);
1547
1548 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_PREF_CONTEXT,
1549 &data);
1550 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1551 }
1552
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_unset_val_last)1553 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_unset_val_last)
1554 {
1555 struct bt_audio_codec_cap codec_cap =
1556 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, TRIPLE_META_DATA);
1557 const uint16_t expected_data = BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED;
1558 const uint8_t *data;
1559 int ret;
1560
1561 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT,
1562 &data);
1563 zassert_equal(ret, sizeof(expected_data), "Unexpected return value %d", ret);
1564 zassert_equal(sys_get_le16(data), expected_data, "Unexpected return value %d", ret);
1565
1566 ret = bt_audio_codec_cap_meta_unset_val(&codec_cap, BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT);
1567 zassert_true(ret >= 0, "Unexpected return value %d", ret);
1568
1569 ret = bt_audio_codec_cap_meta_get_val(&codec_cap, BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT,
1570 &data);
1571 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1572 }
1573
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_pref_context)1574 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_pref_context)
1575 {
1576 const enum bt_audio_context ctx =
1577 BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | BT_AUDIO_CONTEXT_TYPE_MEDIA;
1578 const struct bt_audio_codec_cap codec_cap =
1579 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1580 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PREF_CONTEXT,
1581 BT_BYTES_LIST_LE16(ctx))});
1582 int ret;
1583
1584 ret = bt_audio_codec_cap_meta_get_pref_context(&codec_cap);
1585 zassert_equal(ret, 0x0005, "unexpected return value %d", ret);
1586 }
1587
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_pref_context)1588 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_pref_context)
1589 {
1590 const enum bt_audio_context ctx =
1591 BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | BT_AUDIO_CONTEXT_TYPE_MEDIA;
1592 const enum bt_audio_context new_ctx = BT_AUDIO_CONTEXT_TYPE_NOTIFICATIONS;
1593 struct bt_audio_codec_cap codec_cap =
1594 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1595 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PREF_CONTEXT,
1596 BT_BYTES_LIST_LE16(ctx))});
1597 int ret;
1598
1599 ret = bt_audio_codec_cap_meta_get_pref_context(&codec_cap);
1600 zassert_equal(ret, 0x0005, "Unexpected return value %d", ret);
1601
1602 ret = bt_audio_codec_cap_meta_set_pref_context(&codec_cap, new_ctx);
1603 zassert_true(ret > 0, "Unexpected return value %d", ret);
1604
1605 ret = bt_audio_codec_cap_meta_get_pref_context(&codec_cap);
1606 zassert_equal(ret, 0x0100, "Unexpected return value %d", ret);
1607 }
1608
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_stream_context)1609 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_stream_context)
1610 {
1611 const enum bt_audio_context ctx =
1612 BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | BT_AUDIO_CONTEXT_TYPE_MEDIA;
1613 const struct bt_audio_codec_cap codec_cap =
1614 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1615 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT,
1616 BT_BYTES_LIST_LE16(ctx))});
1617 int ret;
1618
1619 ret = bt_audio_codec_cap_meta_get_stream_context(&codec_cap);
1620 zassert_equal(ret, 0x0005, "unexpected return value %d", ret);
1621 }
1622
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_stream_context)1623 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_stream_context)
1624 {
1625 enum bt_audio_context ctx = BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | BT_AUDIO_CONTEXT_TYPE_MEDIA;
1626 struct bt_audio_codec_cap codec_cap =
1627 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1628 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT,
1629 BT_BYTES_LIST_LE16(ctx))});
1630 int ret;
1631
1632 ret = bt_audio_codec_cap_meta_get_stream_context(&codec_cap);
1633 zassert_equal(ret, 0x0005, "Unexpected return value %d", ret);
1634
1635 ctx = BT_AUDIO_CONTEXT_TYPE_NOTIFICATIONS;
1636 ret = bt_audio_codec_cap_meta_set_stream_context(&codec_cap, ctx);
1637 zassert_true(ret > 0, "Unexpected return value %d", ret);
1638
1639 ret = bt_audio_codec_cap_meta_get_stream_context(&codec_cap);
1640 zassert_equal(ret, 0x0100, "Unexpected return value %d", ret);
1641 }
1642
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_program_info)1643 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_program_info)
1644 {
1645 const uint8_t expected_data[] = {'P', 'r', 'o', 'g', 'r', 'a', 'm', ' ',
1646 'I', 'n', 'f', 'o'};
1647 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1648 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1649 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO,
1650 'P', 'r', 'o', 'g', 'r', 'a', 'm', ' ',
1651 'I', 'n', 'f', 'o')});
1652 const uint8_t *program_data;
1653 int ret;
1654
1655 ret = bt_audio_codec_cap_meta_get_program_info(&codec_cap, &program_data);
1656 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1657 zassert_mem_equal(expected_data, program_data, ARRAY_SIZE(expected_data));
1658 }
1659
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_program_info)1660 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_program_info)
1661 {
1662 const uint8_t expected_data[] = {'P', 'r', 'o', 'g', 'r', 'a',
1663 'm', ' ', 'I', 'n', 'f', 'o'};
1664 const uint8_t new_expected_data[] = {'N', 'e', 'w', ' ', 'i', 'n', 'f', 'o'};
1665 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1666 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1667 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO, 'P', 'r', 'o', 'g', 'r',
1668 'a', 'm', ' ', 'I', 'n', 'f', 'o')});
1669 const uint8_t *program_data;
1670 int ret;
1671
1672 ret = bt_audio_codec_cap_meta_get_program_info(&codec_cap, &program_data);
1673 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1674 zassert_mem_equal(expected_data, program_data, ARRAY_SIZE(expected_data));
1675
1676 ret = bt_audio_codec_cap_meta_set_program_info(&codec_cap, new_expected_data,
1677 ARRAY_SIZE(new_expected_data));
1678 zassert_true(ret > 0, "Unexpected return value %d", ret);
1679
1680 ret = bt_audio_codec_cap_meta_get_program_info(&codec_cap, &program_data);
1681 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
1682 zassert_mem_equal(new_expected_data, program_data, ARRAY_SIZE(new_expected_data));
1683 }
1684
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_lang)1685 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_lang)
1686 {
1687 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1688 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1689 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_LANG, 'e', 'n', 'g')});
1690 char expected_data[] = "eng";
1691 const uint8_t *lang;
1692 int ret;
1693
1694 ret = bt_audio_codec_cap_meta_get_lang(&codec_cap, &lang);
1695 zassert_equal(ret, 0, "Unexpected return value %d", ret);
1696 zassert_mem_equal(expected_data, lang, BT_AUDIO_LANG_SIZE);
1697 }
1698
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_lang)1699 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_lang)
1700 {
1701 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1702 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1703 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_LANG, 'e', 'n', 'g')});
1704 const uint8_t new_expected_data[] = "deu";
1705 char expected_data[] = "eng";
1706 const uint8_t *lang;
1707 int ret;
1708
1709 ret = bt_audio_codec_cap_meta_get_lang(&codec_cap, &lang);
1710 zassert_equal(ret, 0, "Unexpected return value %d", ret);
1711 zassert_mem_equal(expected_data, lang, BT_AUDIO_LANG_SIZE);
1712
1713 ret = bt_audio_codec_cap_meta_set_lang(&codec_cap, new_expected_data);
1714 zassert_true(ret > 0, "Unexpected return value %d", ret);
1715
1716 ret = bt_audio_codec_cap_meta_get_lang(&codec_cap, &lang);
1717 zassert_equal(ret, 0, "Unexpected return value %d", ret);
1718 zassert_mem_equal(new_expected_data, lang, BT_AUDIO_LANG_SIZE);
1719 }
1720
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_ccid_list)1721 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_ccid_list)
1722 {
1723 const uint8_t expected_data[] = {0x05, 0x10, 0x15};
1724 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1725 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1726 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_CCID_LIST, 0x05, 0x10, 0x15)});
1727 const uint8_t *ccid_list;
1728 int ret;
1729
1730 ret = bt_audio_codec_cap_meta_get_ccid_list(&codec_cap, &ccid_list);
1731 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1732 zassert_mem_equal(expected_data, ccid_list, ARRAY_SIZE(expected_data));
1733 }
1734
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_ccid_list)1735 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_ccid_list)
1736 {
1737 const uint8_t expected_data[] = {0x05, 0x10, 0x15};
1738 const uint8_t new_expected_data[] = {0x25, 0x30};
1739 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1740 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1741 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_CCID_LIST, 0x05, 0x10, 0x15)});
1742 const uint8_t *ccid_list;
1743 int ret;
1744
1745 ret = bt_audio_codec_cap_meta_get_ccid_list(&codec_cap, &ccid_list);
1746 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1747 zassert_mem_equal(expected_data, ccid_list, ARRAY_SIZE(expected_data));
1748
1749 ret = bt_audio_codec_cap_meta_set_ccid_list(&codec_cap, new_expected_data,
1750 ARRAY_SIZE(new_expected_data));
1751 zassert_true(ret > 0, "Unexpected return value %d", ret);
1752
1753 ret = bt_audio_codec_cap_meta_get_ccid_list(&codec_cap, &ccid_list);
1754 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
1755 zassert_mem_equal(new_expected_data, ccid_list, ARRAY_SIZE(new_expected_data));
1756 }
1757
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_parental_rating)1758 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_parental_rating)
1759 {
1760 const struct bt_audio_codec_cap codec_cap =
1761 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1762 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1763 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)});
1764 int ret;
1765
1766 ret = bt_audio_codec_cap_meta_get_parental_rating(&codec_cap);
1767 zassert_equal(ret, 0x07, "Unexpected return value %d", ret);
1768 }
1769
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_parental_rating)1770 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_parental_rating)
1771 {
1772 struct bt_audio_codec_cap codec_cap =
1773 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1774 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
1775 BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE)});
1776 int ret;
1777
1778 ret = bt_audio_codec_cap_meta_get_parental_rating(&codec_cap);
1779 zassert_equal(ret, 0x07, "Unexpected return value %d", ret);
1780
1781 ret = bt_audio_codec_cap_meta_set_parental_rating(&codec_cap,
1782 BT_AUDIO_PARENTAL_RATING_AGE_13_OR_ABOVE);
1783 zassert_true(ret > 0, "Unexpected return value %d", ret);
1784
1785 ret = bt_audio_codec_cap_meta_get_parental_rating(&codec_cap);
1786 zassert_equal(ret, 0x0a, "Unexpected return value %d", ret);
1787 }
1788
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_program_info_uri)1789 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_program_info_uri)
1790 {
1791 const uint8_t expected_data[] = {'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm'};
1792 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1793 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1794 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI,
1795 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm')});
1796 const uint8_t *program_info_uri;
1797 int ret;
1798
1799 ret = bt_audio_codec_cap_meta_get_program_info_uri(&codec_cap, &program_info_uri);
1800 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1801 zassert_mem_equal(expected_data, program_info_uri, ARRAY_SIZE(expected_data));
1802 }
1803
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_program_info_uri)1804 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_program_info_uri)
1805 {
1806 const uint8_t expected_data[] = {'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm'};
1807 const uint8_t new_expected_data[] = {'n', 'e', 'w', '.', 'c', 'o', 'm'};
1808 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1809 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1810 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI, 'e', 'x', 'a', 'm',
1811 'p', 'l', 'e', '.', 'c', 'o', 'm')});
1812 const uint8_t *program_info_uri;
1813 int ret;
1814
1815 ret = bt_audio_codec_cap_meta_get_program_info_uri(&codec_cap, &program_info_uri);
1816 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1817 zassert_mem_equal(expected_data, program_info_uri, ARRAY_SIZE(expected_data));
1818
1819 ret = bt_audio_codec_cap_meta_set_program_info_uri(&codec_cap, new_expected_data,
1820 ARRAY_SIZE(new_expected_data));
1821 zassert_true(ret > 0, "Unexpected return value %d", ret);
1822
1823 ret = bt_audio_codec_cap_meta_get_program_info_uri(&codec_cap, &program_info_uri);
1824 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
1825 zassert_mem_equal(new_expected_data, program_info_uri, ARRAY_SIZE(new_expected_data));
1826 }
1827
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_audio_active_state)1828 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_audio_active_state)
1829 {
1830 const struct bt_audio_codec_cap codec_cap =
1831 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1832 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_AUDIO_STATE,
1833 BT_AUDIO_ACTIVE_STATE_ENABLED)});
1834 int ret;
1835
1836 ret = bt_audio_codec_cap_meta_get_audio_active_state(&codec_cap);
1837 zassert_equal(ret, 0x01, "Unexpected return value %d", ret);
1838 }
1839
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_audio_active_state)1840 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_audio_active_state)
1841 {
1842 struct bt_audio_codec_cap codec_cap =
1843 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1844 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_AUDIO_STATE,
1845 BT_AUDIO_ACTIVE_STATE_ENABLED)});
1846 int ret;
1847
1848 ret = bt_audio_codec_cap_meta_get_audio_active_state(&codec_cap);
1849 zassert_equal(ret, 0x01, "Unexpected return value %d", ret);
1850
1851 ret = bt_audio_codec_cap_meta_set_audio_active_state(&codec_cap,
1852 BT_AUDIO_ACTIVE_STATE_DISABLED);
1853 zassert_true(ret > 0, "Unexpected return value %d", ret);
1854
1855 ret = bt_audio_codec_cap_meta_get_audio_active_state(&codec_cap);
1856 zassert_equal(ret, 0x00, "Unexpected return value %d", ret);
1857 }
1858
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag)1859 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag)
1860 {
1861 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1862 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1863 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE)});
1864 int ret;
1865
1866 ret = bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag(&codec_cap);
1867 zassert_equal(ret, 0, "Unexpected return value %d", ret);
1868 }
1869
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_bcast_audio_immediate_rend_flag)1870 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_bcast_audio_immediate_rend_flag)
1871 {
1872 struct bt_audio_codec_cap codec_cap =
1873 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, {});
1874 int ret;
1875
1876 ret = bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag(&codec_cap);
1877 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1878
1879 ret = bt_audio_codec_cap_meta_set_bcast_audio_immediate_rend_flag(&codec_cap);
1880 zassert_true(ret > 0, "Unexpected return value %d", ret);
1881
1882 ret = bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag(&codec_cap);
1883 zassert_equal(ret, 0, "Unexpected return value %d", ret);
1884 }
1885
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_assisted_listening_stream)1886 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_assisted_listening_stream)
1887 {
1888 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1889 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1890 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_ASSISTED_LISTENING_STREAM,
1891 BT_AUDIO_ASSISTED_LISTENING_STREAM_UNSPECIFIED)});
1892 int ret;
1893
1894 ret = bt_audio_codec_cap_meta_get_assisted_listening_stream(&codec_cap);
1895 zassert_equal(ret, 0x00, "Unexpected return value %d", ret);
1896 }
1897
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_assisted_listening_stream)1898 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_assisted_listening_stream)
1899 {
1900 struct bt_audio_codec_cap codec_cap =
1901 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, {});
1902 int ret;
1903
1904 ret = bt_audio_codec_cap_meta_get_assisted_listening_stream(&codec_cap);
1905 zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret);
1906
1907 ret = bt_audio_codec_cap_meta_set_assisted_listening_stream(
1908 &codec_cap, BT_AUDIO_ASSISTED_LISTENING_STREAM_UNSPECIFIED);
1909 zassert_true(ret > 0, "Unexpected return value %d", ret);
1910
1911 ret = bt_audio_codec_cap_meta_get_assisted_listening_stream(&codec_cap);
1912 zassert_equal(ret, 0x00, "Unexpected return value %d", ret);
1913 }
1914
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_broadcast_name)1915 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_broadcast_name)
1916 {
1917 const uint8_t expected_data[] = {'m', 'y', ' ', 'b', 'c', 'a', 's', 't'};
1918 const struct bt_audio_codec_cap codec_cap =
1919 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1920 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_BROADCAST_NAME, 'm',
1921 'y', ' ', 'b', 'c', 'a', 's', 't')});
1922 const uint8_t *broadcast_name;
1923 int ret;
1924
1925 ret = bt_audio_codec_cap_meta_get_broadcast_name(&codec_cap, &broadcast_name);
1926 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1927 zassert_mem_equal(expected_data, broadcast_name, ARRAY_SIZE(expected_data));
1928 }
1929
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_broadcast_name)1930 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_broadcast_name)
1931 {
1932 const uint8_t expected_data[] = {'m', 'y', ' ', 'b', 'c', 'a', 's', 't'};
1933 const uint8_t new_expected_data[] = {'n', 'e', 'w', ' ', 'b', 'c', 'a', 's', 't'};
1934 struct bt_audio_codec_cap codec_cap =
1935 BT_AUDIO_CODEC_CAP(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1936 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_BROADCAST_NAME, 'm',
1937 'y', ' ', 'b', 'c', 'a', 's', 't')});
1938 const uint8_t *broadcast_name;
1939 int ret;
1940
1941 ret = bt_audio_codec_cap_meta_get_broadcast_name(&codec_cap, &broadcast_name);
1942 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1943 zassert_mem_equal(expected_data, broadcast_name, ARRAY_SIZE(expected_data));
1944
1945 ret = bt_audio_codec_cap_meta_set_broadcast_name(&codec_cap, new_expected_data,
1946 ARRAY_SIZE(new_expected_data));
1947 zassert_true(ret > 0, "Unexpected return value %d", ret);
1948
1949 ret = bt_audio_codec_cap_meta_get_broadcast_name(&codec_cap, &broadcast_name);
1950 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
1951 zassert_mem_equal(new_expected_data, broadcast_name, ARRAY_SIZE(new_expected_data));
1952 }
1953
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_extended)1954 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_extended)
1955 {
1956 const uint8_t expected_data[] = {0x00, 0x01, 0x02, 0x03};
1957 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1958 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1959 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_EXTENDED, 0x00, 0x01, 0x02, 0x03)});
1960 const uint8_t *extended_meta;
1961 int ret;
1962
1963 ret = bt_audio_codec_cap_meta_get_extended(&codec_cap, &extended_meta);
1964 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1965 zassert_mem_equal(expected_data, extended_meta, ARRAY_SIZE(expected_data));
1966 }
1967
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_extended)1968 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_extended)
1969 {
1970 const uint8_t expected_data[] = {0x00, 0x01, 0x02, 0x03};
1971 const uint8_t new_expected_data[] = {0x04, 0x05};
1972 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1973 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1974 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_EXTENDED, 0x00, 0x01, 0x02, 0x03)});
1975 const uint8_t *extended_meta;
1976 int ret;
1977
1978 ret = bt_audio_codec_cap_meta_get_extended(&codec_cap, &extended_meta);
1979 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
1980 zassert_mem_equal(expected_data, extended_meta, ARRAY_SIZE(expected_data));
1981
1982 ret = bt_audio_codec_cap_meta_set_extended(&codec_cap, new_expected_data,
1983 ARRAY_SIZE(new_expected_data));
1984 zassert_true(ret > 0, "Unexpected return value %d", ret);
1985
1986 ret = bt_audio_codec_cap_meta_get_extended(&codec_cap, &extended_meta);
1987 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
1988 zassert_mem_equal(new_expected_data, extended_meta, ARRAY_SIZE(new_expected_data));
1989 }
1990
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_get_vendor)1991 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_get_vendor)
1992 {
1993 const uint8_t expected_data[] = {0x00, 0x01, 0x02, 0x03};
1994 const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
1995 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
1996 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_VENDOR, 0x00, 0x01, 0x02, 0x03)});
1997 const uint8_t *vendor_meta;
1998 int ret;
1999
2000 ret = bt_audio_codec_cap_meta_get_vendor(&codec_cap, &vendor_meta);
2001 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
2002 zassert_mem_equal(expected_data, vendor_meta, ARRAY_SIZE(expected_data));
2003 }
2004
ZTEST(audio_codec_test_suite,test_bt_audio_codec_cap_meta_set_vendor)2005 ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_vendor)
2006 {
2007 const uint8_t expected_data[] = {0x00, 0x01, 0x02, 0x03};
2008 const uint8_t new_expected_data[] = {0x04, 0x05, 0x06, 0x07, 0x08};
2009 struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP(
2010 BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {},
2011 {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_VENDOR, 0x00, 0x01, 0x02, 0x03)});
2012 const uint8_t *extended_meta;
2013 int ret;
2014
2015 ret = bt_audio_codec_cap_meta_get_vendor(&codec_cap, &extended_meta);
2016 zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret);
2017 zassert_mem_equal(expected_data, extended_meta, ARRAY_SIZE(expected_data));
2018
2019 ret = bt_audio_codec_cap_meta_set_vendor(&codec_cap, new_expected_data,
2020 ARRAY_SIZE(new_expected_data));
2021 zassert_true(ret > 0, "Unexpected return value %d", ret);
2022
2023 ret = bt_audio_codec_cap_meta_get_vendor(&codec_cap, &extended_meta);
2024 zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret);
2025 zassert_mem_equal(new_expected_data, extended_meta, ARRAY_SIZE(new_expected_data));
2026 }
2027