1 /*
2  * Copyright 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.bluetooth;
18 
19 import androidx.test.runner.AndroidJUnit4;
20 
21 import com.google.common.truth.Expect;
22 
23 import org.junit.Rule;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 
27 import java.util.List;
28 
29 /** Unit test cases for {@link BluetoothCodecStatus}. */
30 @RunWith(AndroidJUnit4.class)
31 public class BluetoothCodecStatusTest {
32 
33     @Rule public Expect expect = Expect.create();
34 
35     // Codec configs: A and B are same; C is different
36     private static final BluetoothCodecConfig CONFIG_A =
37             buildBluetoothCodecConfig(
38                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
39                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
40                     BluetoothCodecConfig.SAMPLE_RATE_44100,
41                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
42                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
43                     1000,
44                     2000,
45                     3000,
46                     4000);
47 
48     private static final BluetoothCodecConfig CONFIG_B =
49             buildBluetoothCodecConfig(
50                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
51                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
52                     BluetoothCodecConfig.SAMPLE_RATE_44100,
53                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
54                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
55                     1000,
56                     2000,
57                     3000,
58                     4000);
59 
60     private static final BluetoothCodecConfig CONFIG_C =
61             buildBluetoothCodecConfig(
62                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
63                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
64                     BluetoothCodecConfig.SAMPLE_RATE_44100,
65                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
66                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
67                     1000,
68                     2000,
69                     3000,
70                     4000);
71 
72     // Local capabilities: A and B are same; C is different
73     private static final BluetoothCodecConfig LOCAL_CAPABILITY_1_A =
74             buildBluetoothCodecConfig(
75                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
76                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
77                     BluetoothCodecConfig.SAMPLE_RATE_44100 | BluetoothCodecConfig.SAMPLE_RATE_48000,
78                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
79                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
80                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
81                     1000,
82                     2000,
83                     3000,
84                     4000);
85 
86     private static final BluetoothCodecConfig LOCAL_CAPABILITY_1_B =
87             buildBluetoothCodecConfig(
88                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
89                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
90                     BluetoothCodecConfig.SAMPLE_RATE_44100 | BluetoothCodecConfig.SAMPLE_RATE_48000,
91                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
92                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
93                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
94                     1000,
95                     2000,
96                     3000,
97                     4000);
98 
99     private static final BluetoothCodecConfig LOCAL_CAPABILITY_1_C =
100             buildBluetoothCodecConfig(
101                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
102                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
103                     BluetoothCodecConfig.SAMPLE_RATE_44100 | BluetoothCodecConfig.SAMPLE_RATE_48000,
104                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
105                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
106                     1000,
107                     2000,
108                     3000,
109                     4000);
110 
111     private static final BluetoothCodecConfig LOCAL_CAPABILITY_2_A =
112             buildBluetoothCodecConfig(
113                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
114                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
115                     BluetoothCodecConfig.SAMPLE_RATE_44100 | BluetoothCodecConfig.SAMPLE_RATE_48000,
116                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
117                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
118                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
119                     1000,
120                     2000,
121                     3000,
122                     4000);
123 
124     private static final BluetoothCodecConfig LOCAL_CAPABILITY_2_B =
125             buildBluetoothCodecConfig(
126                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
127                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
128                     BluetoothCodecConfig.SAMPLE_RATE_44100 | BluetoothCodecConfig.SAMPLE_RATE_48000,
129                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
130                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
131                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
132                     1000,
133                     2000,
134                     3000,
135                     4000);
136 
137     private static final BluetoothCodecConfig LOCAL_CAPABILITY_2_C =
138             buildBluetoothCodecConfig(
139                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
140                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
141                     BluetoothCodecConfig.SAMPLE_RATE_44100 | BluetoothCodecConfig.SAMPLE_RATE_48000,
142                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
143                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
144                     1000,
145                     2000,
146                     3000,
147                     4000);
148 
149     private static final BluetoothCodecConfig LOCAL_CAPABILITY_3_A =
150             buildBluetoothCodecConfig(
151                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX,
152                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
153                     BluetoothCodecConfig.SAMPLE_RATE_44100 | BluetoothCodecConfig.SAMPLE_RATE_48000,
154                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
155                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
156                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
157                     1000,
158                     2000,
159                     3000,
160                     4000);
161 
162     private static final BluetoothCodecConfig LOCAL_CAPABILITY_3_B =
163             buildBluetoothCodecConfig(
164                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX,
165                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
166                     BluetoothCodecConfig.SAMPLE_RATE_44100 | BluetoothCodecConfig.SAMPLE_RATE_48000,
167                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
168                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
169                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
170                     1000,
171                     2000,
172                     3000,
173                     4000);
174 
175     private static final BluetoothCodecConfig LOCAL_CAPABILITY_3_C =
176             buildBluetoothCodecConfig(
177                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX,
178                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
179                     BluetoothCodecConfig.SAMPLE_RATE_44100 | BluetoothCodecConfig.SAMPLE_RATE_48000,
180                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
181                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
182                     1000,
183                     2000,
184                     3000,
185                     4000);
186 
187     private static final BluetoothCodecConfig LOCAL_CAPABILITY_4_A =
188             buildBluetoothCodecConfig(
189                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD,
190                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
191                     BluetoothCodecConfig.SAMPLE_RATE_44100 | BluetoothCodecConfig.SAMPLE_RATE_48000,
192                     BluetoothCodecConfig.BITS_PER_SAMPLE_24,
193                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
194                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
195                     1000,
196                     2000,
197                     3000,
198                     4000);
199 
200     private static final BluetoothCodecConfig LOCAL_CAPABILITY_4_B =
201             buildBluetoothCodecConfig(
202                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD,
203                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
204                     BluetoothCodecConfig.SAMPLE_RATE_44100 | BluetoothCodecConfig.SAMPLE_RATE_48000,
205                     BluetoothCodecConfig.BITS_PER_SAMPLE_24,
206                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
207                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
208                     1000,
209                     2000,
210                     3000,
211                     4000);
212 
213     private static final BluetoothCodecConfig LOCAL_CAPABILITY_4_C =
214             buildBluetoothCodecConfig(
215                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD,
216                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
217                     BluetoothCodecConfig.SAMPLE_RATE_44100 | BluetoothCodecConfig.SAMPLE_RATE_48000,
218                     BluetoothCodecConfig.BITS_PER_SAMPLE_24,
219                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
220                     1000,
221                     2000,
222                     3000,
223                     4000);
224 
225     private static final BluetoothCodecConfig LOCAL_CAPABILITY_5_A =
226             buildBluetoothCodecConfig(
227                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC,
228                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
229                     BluetoothCodecConfig.SAMPLE_RATE_44100
230                             | BluetoothCodecConfig.SAMPLE_RATE_48000
231                             | BluetoothCodecConfig.SAMPLE_RATE_88200
232                             | BluetoothCodecConfig.SAMPLE_RATE_96000,
233                     BluetoothCodecConfig.BITS_PER_SAMPLE_16
234                             | BluetoothCodecConfig.BITS_PER_SAMPLE_24
235                             | BluetoothCodecConfig.BITS_PER_SAMPLE_32,
236                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
237                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
238                     1000,
239                     2000,
240                     3000,
241                     4000);
242 
243     private static final BluetoothCodecConfig LOCAL_CAPABILITY_5_B =
244             buildBluetoothCodecConfig(
245                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC,
246                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
247                     BluetoothCodecConfig.SAMPLE_RATE_44100
248                             | BluetoothCodecConfig.SAMPLE_RATE_48000
249                             | BluetoothCodecConfig.SAMPLE_RATE_88200
250                             | BluetoothCodecConfig.SAMPLE_RATE_96000,
251                     BluetoothCodecConfig.BITS_PER_SAMPLE_16
252                             | BluetoothCodecConfig.BITS_PER_SAMPLE_24
253                             | BluetoothCodecConfig.BITS_PER_SAMPLE_32,
254                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
255                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
256                     1000,
257                     2000,
258                     3000,
259                     4000);
260 
261     private static final BluetoothCodecConfig LOCAL_CAPABILITY_5_C =
262             buildBluetoothCodecConfig(
263                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC,
264                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
265                     BluetoothCodecConfig.SAMPLE_RATE_44100
266                             | BluetoothCodecConfig.SAMPLE_RATE_48000
267                             | BluetoothCodecConfig.SAMPLE_RATE_88200
268                             | BluetoothCodecConfig.SAMPLE_RATE_96000,
269                     BluetoothCodecConfig.BITS_PER_SAMPLE_16
270                             | BluetoothCodecConfig.BITS_PER_SAMPLE_24
271                             | BluetoothCodecConfig.BITS_PER_SAMPLE_32,
272                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
273                     1000,
274                     2000,
275                     3000,
276                     4000);
277 
278     // Selectable capabilities: A and B are same; C is different
279     private static final BluetoothCodecConfig SELECTABE_CAPABILITY_1_A =
280             buildBluetoothCodecConfig(
281                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
282                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
283                     BluetoothCodecConfig.SAMPLE_RATE_44100,
284                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
285                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
286                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
287                     1000,
288                     2000,
289                     3000,
290                     4000);
291 
292     private static final BluetoothCodecConfig SELECTABE_CAPABILITY_1_B =
293             buildBluetoothCodecConfig(
294                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
295                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
296                     BluetoothCodecConfig.SAMPLE_RATE_44100,
297                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
298                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
299                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
300                     1000,
301                     2000,
302                     3000,
303                     4000);
304 
305     private static final BluetoothCodecConfig SELECTABE_CAPABILITY_1_C =
306             buildBluetoothCodecConfig(
307                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
308                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
309                     BluetoothCodecConfig.SAMPLE_RATE_44100,
310                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
311                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
312                     1000,
313                     2000,
314                     3000,
315                     4000);
316 
317     private static final BluetoothCodecConfig SELECTABE_CAPABILITY_2_A =
318             buildBluetoothCodecConfig(
319                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
320                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
321                     BluetoothCodecConfig.SAMPLE_RATE_44100,
322                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
323                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
324                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
325                     1000,
326                     2000,
327                     3000,
328                     4000);
329 
330     private static final BluetoothCodecConfig SELECTABE_CAPABILITY_2_B =
331             buildBluetoothCodecConfig(
332                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
333                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
334                     BluetoothCodecConfig.SAMPLE_RATE_44100,
335                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
336                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
337                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
338                     1000,
339                     2000,
340                     3000,
341                     4000);
342 
343     private static final BluetoothCodecConfig SELECTABE_CAPABILITY_2_C =
344             buildBluetoothCodecConfig(
345                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
346                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
347                     BluetoothCodecConfig.SAMPLE_RATE_44100,
348                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
349                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
350                     1000,
351                     2000,
352                     3000,
353                     4000);
354 
355     private static final BluetoothCodecConfig SELECTABE_CAPABILITY_3_A =
356             buildBluetoothCodecConfig(
357                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX,
358                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
359                     BluetoothCodecConfig.SAMPLE_RATE_44100,
360                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
361                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
362                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
363                     1000,
364                     2000,
365                     3000,
366                     4000);
367 
368     private static final BluetoothCodecConfig SELECTABE_CAPABILITY_3_B =
369             buildBluetoothCodecConfig(
370                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX,
371                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
372                     BluetoothCodecConfig.SAMPLE_RATE_44100,
373                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
374                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
375                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
376                     1000,
377                     2000,
378                     3000,
379                     4000);
380 
381     private static final BluetoothCodecConfig SELECTABE_CAPABILITY_3_C =
382             buildBluetoothCodecConfig(
383                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX,
384                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
385                     BluetoothCodecConfig.SAMPLE_RATE_44100,
386                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
387                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
388                     1000,
389                     2000,
390                     3000,
391                     4000);
392 
393     private static final BluetoothCodecConfig SELECTABE_CAPABILITY_4_A =
394             buildBluetoothCodecConfig(
395                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD,
396                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
397                     BluetoothCodecConfig.SAMPLE_RATE_44100,
398                     BluetoothCodecConfig.BITS_PER_SAMPLE_24,
399                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
400                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
401                     1000,
402                     2000,
403                     3000,
404                     4000);
405 
406     private static final BluetoothCodecConfig SELECTABE_CAPABILITY_4_B =
407             buildBluetoothCodecConfig(
408                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD,
409                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
410                     BluetoothCodecConfig.SAMPLE_RATE_44100,
411                     BluetoothCodecConfig.BITS_PER_SAMPLE_24,
412                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
413                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
414                     1000,
415                     2000,
416                     3000,
417                     4000);
418 
419     private static final BluetoothCodecConfig SELECTABE_CAPABILITY_4_C =
420             buildBluetoothCodecConfig(
421                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD,
422                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
423                     BluetoothCodecConfig.SAMPLE_RATE_44100,
424                     BluetoothCodecConfig.BITS_PER_SAMPLE_24,
425                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
426                     1000,
427                     2000,
428                     3000,
429                     4000);
430 
431     private static final BluetoothCodecConfig SELECTABE_CAPABILITY_5_A =
432             buildBluetoothCodecConfig(
433                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC,
434                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
435                     BluetoothCodecConfig.SAMPLE_RATE_44100
436                             | BluetoothCodecConfig.SAMPLE_RATE_48000
437                             | BluetoothCodecConfig.SAMPLE_RATE_88200
438                             | BluetoothCodecConfig.SAMPLE_RATE_96000,
439                     BluetoothCodecConfig.BITS_PER_SAMPLE_16
440                             | BluetoothCodecConfig.BITS_PER_SAMPLE_24
441                             | BluetoothCodecConfig.BITS_PER_SAMPLE_32,
442                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
443                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
444                     1000,
445                     2000,
446                     3000,
447                     4000);
448 
449     private static final BluetoothCodecConfig SELECTABE_CAPABILITY_5_B =
450             buildBluetoothCodecConfig(
451                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC,
452                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
453                     BluetoothCodecConfig.SAMPLE_RATE_44100
454                             | BluetoothCodecConfig.SAMPLE_RATE_48000
455                             | BluetoothCodecConfig.SAMPLE_RATE_88200
456                             | BluetoothCodecConfig.SAMPLE_RATE_96000,
457                     BluetoothCodecConfig.BITS_PER_SAMPLE_16
458                             | BluetoothCodecConfig.BITS_PER_SAMPLE_24
459                             | BluetoothCodecConfig.BITS_PER_SAMPLE_32,
460                     BluetoothCodecConfig.CHANNEL_MODE_STEREO
461                             | BluetoothCodecConfig.CHANNEL_MODE_MONO,
462                     1000,
463                     2000,
464                     3000,
465                     4000);
466 
467     private static final BluetoothCodecConfig SELECTABE_CAPABILITY_5_C =
468             buildBluetoothCodecConfig(
469                     BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC,
470                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
471                     BluetoothCodecConfig.SAMPLE_RATE_44100
472                             | BluetoothCodecConfig.SAMPLE_RATE_48000
473                             | BluetoothCodecConfig.SAMPLE_RATE_88200
474                             | BluetoothCodecConfig.SAMPLE_RATE_96000,
475                     BluetoothCodecConfig.BITS_PER_SAMPLE_16
476                             | BluetoothCodecConfig.BITS_PER_SAMPLE_24
477                             | BluetoothCodecConfig.BITS_PER_SAMPLE_32,
478                     BluetoothCodecConfig.CHANNEL_MODE_STEREO,
479                     1000,
480                     2000,
481                     3000,
482                     4000);
483 
484     private static final List<BluetoothCodecConfig> LOCAL_CAPABILITY_A =
485             List.of(
486                     LOCAL_CAPABILITY_1_A,
487                     LOCAL_CAPABILITY_2_A,
488                     LOCAL_CAPABILITY_3_A,
489                     LOCAL_CAPABILITY_4_A,
490                     LOCAL_CAPABILITY_5_A);
491 
492     private static final List<BluetoothCodecConfig> LOCAL_CAPABILITY_B =
493             List.of(
494                     LOCAL_CAPABILITY_1_B,
495                     LOCAL_CAPABILITY_2_B,
496                     LOCAL_CAPABILITY_3_B,
497                     LOCAL_CAPABILITY_4_B,
498                     LOCAL_CAPABILITY_5_B);
499 
500     private static final List<BluetoothCodecConfig> LOCAL_CAPABILITY_B_REORDERED =
501             List.of(
502                     LOCAL_CAPABILITY_5_B,
503                     LOCAL_CAPABILITY_4_B,
504                     LOCAL_CAPABILITY_2_B,
505                     LOCAL_CAPABILITY_3_B,
506                     LOCAL_CAPABILITY_1_B);
507 
508     private static final List<BluetoothCodecConfig> LOCAL_CAPABILITY_C =
509             List.of(
510                     LOCAL_CAPABILITY_1_C,
511                     LOCAL_CAPABILITY_2_C,
512                     LOCAL_CAPABILITY_3_C,
513                     LOCAL_CAPABILITY_4_C,
514                     LOCAL_CAPABILITY_5_C);
515 
516     private static final List<BluetoothCodecConfig> SELECTABLE_CAPABILITY_A =
517             List.of(
518                     SELECTABE_CAPABILITY_1_A,
519                     SELECTABE_CAPABILITY_2_A,
520                     SELECTABE_CAPABILITY_3_A,
521                     SELECTABE_CAPABILITY_4_A,
522                     SELECTABE_CAPABILITY_5_A);
523 
524     private static final List<BluetoothCodecConfig> SELECTABLE_CAPABILITY_B =
525             List.of(
526                     SELECTABE_CAPABILITY_1_B,
527                     SELECTABE_CAPABILITY_2_B,
528                     SELECTABE_CAPABILITY_3_B,
529                     SELECTABE_CAPABILITY_4_B,
530                     SELECTABE_CAPABILITY_5_B);
531 
532     private static final List<BluetoothCodecConfig> SELECTABLE_CAPABILITY_B_REORDERED =
533             List.of(
534                     SELECTABE_CAPABILITY_5_B,
535                     SELECTABE_CAPABILITY_4_B,
536                     SELECTABE_CAPABILITY_2_B,
537                     SELECTABE_CAPABILITY_3_B,
538                     SELECTABE_CAPABILITY_1_B);
539 
540     private static final List<BluetoothCodecConfig> SELECTABLE_CAPABILITY_C =
541             List.of(
542                     SELECTABE_CAPABILITY_1_C,
543                     SELECTABE_CAPABILITY_2_C,
544                     SELECTABE_CAPABILITY_3_C,
545                     SELECTABE_CAPABILITY_4_C,
546                     SELECTABE_CAPABILITY_5_C);
547 
548     private static final BluetoothCodecStatus BCS_A =
549             new BluetoothCodecStatus(CONFIG_A, LOCAL_CAPABILITY_A, SELECTABLE_CAPABILITY_A);
550     private static final BluetoothCodecStatus BCS_B =
551             new BluetoothCodecStatus(CONFIG_B, LOCAL_CAPABILITY_B, SELECTABLE_CAPABILITY_B);
552     private static final BluetoothCodecStatus BCS_B_REORDERED =
553             new BluetoothCodecStatus(
554                     CONFIG_B, LOCAL_CAPABILITY_B_REORDERED, SELECTABLE_CAPABILITY_B_REORDERED);
555     private static final BluetoothCodecStatus BCS_C =
556             new BluetoothCodecStatus(CONFIG_C, LOCAL_CAPABILITY_C, SELECTABLE_CAPABILITY_C);
557 
558     @Test
testBluetoothCodecStatus_get_methods()559     public void testBluetoothCodecStatus_get_methods() {
560         expect.that(BCS_A.getCodecConfig()).isEqualTo(CONFIG_A);
561         expect.that(BCS_A.getCodecConfig()).isEqualTo(CONFIG_B);
562         expect.that(BCS_A.getCodecConfig()).isNotEqualTo(CONFIG_C);
563 
564         expect.that(BCS_A.getCodecsLocalCapabilities()).isEqualTo(LOCAL_CAPABILITY_A);
565         expect.that(BCS_A.getCodecsLocalCapabilities()).isEqualTo(LOCAL_CAPABILITY_B);
566         expect.that(BCS_A.getCodecsLocalCapabilities()).isNotEqualTo(LOCAL_CAPABILITY_C);
567 
568         expect.that(BCS_A.getCodecsSelectableCapabilities()).isEqualTo(SELECTABLE_CAPABILITY_A);
569         expect.that(BCS_A.getCodecsSelectableCapabilities()).isEqualTo(SELECTABLE_CAPABILITY_B);
570         expect.that(BCS_A.getCodecsSelectableCapabilities()).isNotEqualTo(SELECTABLE_CAPABILITY_C);
571     }
572 
573     @Test
testBluetoothCodecStatus_equals()574     public void testBluetoothCodecStatus_equals() {
575         expect.that(BCS_A).isEqualTo(BCS_B);
576         expect.that(BCS_B).isEqualTo(BCS_A);
577         expect.that(BCS_A).isEqualTo(BCS_B_REORDERED);
578         expect.that(BCS_B_REORDERED).isEqualTo(BCS_A);
579         expect.that(BCS_A).isNotEqualTo(BCS_C);
580         expect.that(BCS_C).isNotEqualTo(BCS_A);
581     }
582 
buildBluetoothCodecConfig( int sourceCodecType, int codecPriority, int sampleRate, int bitsPerSample, int channelMode, long codecSpecific1, long codecSpecific2, long codecSpecific3, long codecSpecific4)583     private static BluetoothCodecConfig buildBluetoothCodecConfig(
584             int sourceCodecType,
585             int codecPriority,
586             int sampleRate,
587             int bitsPerSample,
588             int channelMode,
589             long codecSpecific1,
590             long codecSpecific2,
591             long codecSpecific3,
592             long codecSpecific4) {
593         return new BluetoothCodecConfig.Builder()
594                 .setCodecType(sourceCodecType)
595                 .setCodecPriority(codecPriority)
596                 .setSampleRate(sampleRate)
597                 .setBitsPerSample(bitsPerSample)
598                 .setChannelMode(channelMode)
599                 .setCodecSpecific1(codecSpecific1)
600                 .setCodecSpecific2(codecSpecific2)
601                 .setCodecSpecific3(codecSpecific3)
602                 .setCodecSpecific4(codecSpecific4)
603                 .build();
604     }
605 }
606