Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Jakub Pawlowski | 5b790fe | 2017-09-18 09:00:20 -0700 | [diff] [blame] | 3 | * Copyright 2016 The Android Open Source Project |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 19 | #include <dlfcn.h> |
| 20 | |
| 21 | #include <set> |
Pavlin Radoslavov | a6ba5ac | 2017-01-31 20:51:06 -0800 | [diff] [blame] | 22 | #include <vector> |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 23 | |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 24 | #include <gtest/gtest.h> |
| 25 | |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 26 | #include "stack/include/a2dp_aac.h" |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 27 | #include "stack/include/a2dp_api.h" |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 28 | #include "stack/include/a2dp_codec_api.h" |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 29 | #include "stack/include/a2dp_sbc.h" |
| 30 | #include "stack/include/a2dp_vendor.h" |
| 31 | |
| 32 | namespace { |
| 33 | const uint8_t codec_info_sbc[AVDT_CODEC_SIZE] = { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 34 | 6, // Length (A2DP_SBC_INFO_LEN) |
| 35 | 0, // Media Type: AVDT_MEDIA_TYPE_AUDIO |
| 36 | 0, // Media Codec Type: A2DP_MEDIA_CT_SBC |
| 37 | 0x20 | 0x01, // Sample Frequency: A2DP_SBC_IE_SAMP_FREQ_44 | |
| 38 | // Channel Mode: A2DP_SBC_IE_CH_MD_JOINT |
| 39 | 0x10 | 0x04 | 0x01, // Block Length: A2DP_SBC_IE_BLOCKS_16 | |
| 40 | // Subbands: A2DP_SBC_IE_SUBBAND_8 | |
| 41 | // Allocation Method: A2DP_SBC_IE_ALLOC_MD_L |
| 42 | 2, // MinimumBitpool Value: A2DP_SBC_IE_MIN_BITPOOL |
| 43 | 53, // Maximum Bitpool Value: A2DP_SBC_MAX_BITPOOL |
| 44 | 7, // Dummy |
| 45 | 8, // Dummy |
| 46 | 9 // Dummy |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
koh.changseok | 444ea2c | 2017-07-04 02:37:42 +0900 | [diff] [blame] | 49 | const uint8_t codec_info_sbc_capability[AVDT_CODEC_SIZE] = { |
| 50 | 6, // Length (A2DP_SBC_INFO_LEN) |
| 51 | 0, // Media Type: AVDT_MEDIA_TYPE_AUDIO |
| 52 | 0, // Media Codec Type: A2DP_MEDIA_CT_SBC |
| 53 | 0x20 | // Sample Frequency: A2DP_SBC_IE_SAMP_FREQ_44 | |
| 54 | 0x08 | 0x01, // Channel Mode: A2DP_SBC_IE_CH_MD_MONO | |
| 55 | // A2DP_SBC_IE_CH_MD_JOINT |
| 56 | 0x80 | 0x40 | 0x20 | 0x10 | // Block Length: A2DP_SBC_IE_BLOCKS_4 | |
| 57 | // A2DP_SBC_IE_BLOCKS_8 | |
| 58 | // A2DP_SBC_IE_BLOCKS_12 | |
| 59 | // A2DP_SBC_IE_BLOCKS_16 | |
| 60 | 0x04 | // Subbands: A2DP_SBC_IE_SUBBAND_8 | |
| 61 | 0x01, // Allocation Method: A2DP_SBC_IE_ALLOC_MD_L |
| 62 | 2, // MinimumBitpool Value: A2DP_SBC_IE_MIN_BITPOOL |
| 63 | 53, // Maximum Bitpool Value: A2DP_SBC_MAX_BITPOOL |
| 64 | 7, // Dummy |
| 65 | 8, // Dummy |
| 66 | 9 // Dummy |
| 67 | }; |
| 68 | |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 69 | const uint8_t codec_info_sbc_sink_capability[AVDT_CODEC_SIZE] = { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 70 | 6, // Length (A2DP_SBC_INFO_LEN) |
| 71 | 0, // Media Type: AVDT_MEDIA_TYPE_AUDIO |
| 72 | 0, // Media Codec Type: A2DP_MEDIA_CT_SBC |
| 73 | 0x20 | 0x10 | // Sample Frequency: A2DP_SBC_IE_SAMP_FREQ_44 | |
| 74 | // A2DP_SBC_IE_SAMP_FREQ_48 | |
| 75 | 0x08 | 0x04 | 0x02 | 0x01, // Channel Mode: A2DP_SBC_IE_CH_MD_MONO | |
| 76 | // A2DP_SBC_IE_CH_MD_DUAL | |
| 77 | // A2DP_SBC_IE_CH_MD_STEREO | |
| 78 | // A2DP_SBC_IE_CH_MD_JOINT |
| 79 | 0x80 | 0x40 | 0x20 | 0x10 | // Block Length: A2DP_SBC_IE_BLOCKS_4 | |
| 80 | // A2DP_SBC_IE_BLOCKS_8 | |
| 81 | // A2DP_SBC_IE_BLOCKS_12 | |
| 82 | // A2DP_SBC_IE_BLOCKS_16 | |
| 83 | 0x08 | 0x04 | // Subbands: A2DP_SBC_IE_SUBBAND_4 | |
| 84 | // A2DP_SBC_IE_SUBBAND_8 | |
| 85 | 0x02 | 0x01, // Allocation Method: A2DP_SBC_IE_ALLOC_MD_S | |
| 86 | // A2DP_SBC_IE_ALLOC_MD_L |
| 87 | 2, // MinimumBitpool Value: A2DP_SBC_IE_MIN_BITPOOL |
| 88 | 53, // Maximum Bitpool Value: A2DP_SBC_MAX_BITPOOL |
| 89 | 7, // Dummy |
| 90 | 8, // Dummy |
| 91 | 9 // Dummy |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 94 | const uint8_t codec_info_aac[AVDT_CODEC_SIZE] = { |
| 95 | 8, // Length (A2DP_AAC_INFO_LEN) |
| 96 | 0, // Media Type: AVDT_MEDIA_TYPE_AUDIO |
| 97 | 2, // Media Codec Type: A2DP_MEDIA_CT_AAC |
| 98 | 0x80, // Object Type: A2DP_AAC_OBJECT_TYPE_MPEG2_LC |
| 99 | 0x01, // Sampling Frequency: A2DP_AAC_SAMPLING_FREQ_44100 |
| 100 | 0x04, // Channels: A2DP_AAC_CHANNEL_MODE_STEREO |
| 101 | 0x00 | 0x4, // Variable Bit Rate: |
| 102 | // A2DP_AAC_VARIABLE_BIT_RATE_DISABLED |
| 103 | // Bit Rate: 320000 = 0x4e200 |
| 104 | 0xe2, // Bit Rate: 320000 = 0x4e200 |
| 105 | 0x00, // Bit Rate: 320000 = 0x4e200 |
| 106 | 7, // Dummy |
| 107 | 8, // Dummy |
| 108 | 9 // Dummy |
| 109 | }; |
| 110 | |
| 111 | const uint8_t codec_info_aac_capability[AVDT_CODEC_SIZE] = { |
Pavlin Radoslavov | 858b6a1 | 2017-06-19 21:12:37 -0700 | [diff] [blame] | 112 | 8, // Length (A2DP_AAC_INFO_LEN) |
| 113 | 0, // Media Type: AVDT_MEDIA_TYPE_AUDIO |
| 114 | 2, // Media Codec Type: A2DP_MEDIA_CT_AAC |
| 115 | 0x80, // Object Type: A2DP_AAC_OBJECT_TYPE_MPEG2_LC |
| 116 | 0x01, // Sampling Frequency: A2DP_AAC_SAMPLING_FREQ_44100 |
| 117 | // TODO: AAC 48.0kHz sampling rate should be added back - see b/62301376 |
| 118 | 0x04, // Channels: A2DP_AAC_CHANNEL_MODE_STEREO |
| 119 | 0x00 | 0x4, // Variable Bit Rate: |
| 120 | // A2DP_AAC_VARIABLE_BIT_RATE_DISABLED |
| 121 | // Bit Rate: 320000 = 0x4e200 |
| 122 | 0xe2, // Bit Rate: 320000 = 0x4e200 |
| 123 | 0x00, // Bit Rate: 320000 = 0x4e200 |
| 124 | 7, // Dummy |
| 125 | 8, // Dummy |
| 126 | 9 // Dummy |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | const uint8_t codec_info_aac_sink_capability[AVDT_CODEC_SIZE] = { |
| 130 | 8, // Length (A2DP_AAC_INFO_LEN) |
| 131 | 0, // Media Type: AVDT_MEDIA_TYPE_AUDIO |
| 132 | 2, // Media Codec Type: A2DP_MEDIA_CT_AAC |
| 133 | 0x80 | 0x40 | 0x20 | 0x10, // Object Type: A2DP_AAC_OBJECT_TYPE_MPEG2_LC | |
| 134 | // A2DP_AAC_OBJECT_TYPE_MPEG4_LC |
| 135 | // A2DP_AAC_OBJECT_TYPE_MPEG4_LTP |
| 136 | // A2DP_AAC_OBJECT_TYPE_MPEG4_SCALABLE |
| 137 | 0x01, // Sampling Frequency: A2DP_AAC_SAMPLING_FREQ_44100 |
| 138 | 0x80 | 0x20 | 0x10 | 0x08 | 0x04, // Sampling Frequency: |
| 139 | // A2DP_AAC_SAMPLING_FREQ_48000 | |
| 140 | // A2DP_AAC_SAMPLING_FREQ_88200 | |
| 141 | // A2DP_AAC_SAMPLING_FREQ_96000 | |
| 142 | // Channels: |
| 143 | // A2DP_AAC_CHANNEL_MODE_MONO | |
| 144 | // A2DP_AAC_CHANNEL_MODE_STEREO |
| 145 | 0x80 | 0x4, // Variable Bit Rate: |
| 146 | // A2DP_AAC_VARIABLE_BIT_RATE_ENABLED |
| 147 | // Bit Rate: 320000 = 0x4e200 |
| 148 | 0xe2, // Bit Rate: 320000 = 0x4e200 |
| 149 | 0x00, // Bit Rate: 320000 = 0x4e200 |
| 150 | 7, // Dummy |
| 151 | 8, // Dummy |
| 152 | 9 // Dummy |
| 153 | }; |
| 154 | |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 155 | const uint8_t codec_info_non_a2dp[AVDT_CODEC_SIZE] = { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 156 | 8, // Length |
| 157 | 0, // Media Type: AVDT_MEDIA_TYPE_AUDIO |
| 158 | 0xFF, // Media Codec Type: A2DP_MEDIA_CT_NON_A2DP |
| 159 | 3, 4, 0, 0, // Vendor ID: LSB first, upper two octets should be 0 |
| 160 | 7, 8, // Codec ID: LSB first |
| 161 | 9 // Dummy |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | const uint8_t codec_info_non_a2dp_dummy[AVDT_CODEC_SIZE] = { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 165 | 8, // Length |
| 166 | 0, // Media Type: AVDT_MEDIA_TYPE_AUDIO |
| 167 | 0xFF, // Media Codec Type: A2DP_MEDIA_CT_NON_A2DP |
| 168 | 3, 4, 0, 0, // Vendor ID: LSB first, upper two octets should be 0 |
| 169 | 7, 8, // Codec ID: LSB first |
| 170 | 10 // Dummy |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 171 | }; |
| 172 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 173 | static const char* APTX_ENCODER_LIB_NAME = "libaptX_encoder.so"; |
| 174 | static const char* APTX_HD_ENCODER_LIB_NAME = "libaptXHD_encoder.so"; |
| 175 | static const char* LDAC_ENCODER_LIB_NAME = "libldacBT_enc.so"; |
Chisato Kenmochi | f57c428 | 2018-08-10 20:44:05 +0900 | [diff] [blame] | 176 | static const char* LDAC_DECODER_LIB_NAME = "libldacBT_dec.so"; |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 177 | |
| 178 | static bool has_shared_library(const char* name) { |
| 179 | void* lib_handle = dlopen(name, RTLD_NOW); |
| 180 | if (lib_handle != nullptr) { |
| 181 | dlclose(lib_handle); |
| 182 | return true; |
| 183 | } |
| 184 | return false; |
| 185 | } |
| 186 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 187 | } // namespace |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 188 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 189 | class StackA2dpTest : public ::testing::Test { |
| 190 | protected: |
| 191 | StackA2dpTest() { |
| 192 | // Create the set with all supported codecs |
| 193 | for (int i = BTAV_A2DP_CODEC_INDEX_MIN; i < BTAV_A2DP_CODEC_INDEX_MAX; |
| 194 | i++) { |
| 195 | btav_a2dp_codec_index_t codec_index = |
| 196 | static_cast<btav_a2dp_codec_index_t>(i); |
| 197 | |
| 198 | bool supported = false; |
| 199 | switch (codec_index) { |
| 200 | case BTAV_A2DP_CODEC_INDEX_SOURCE_SBC: |
| 201 | supported = true; |
| 202 | break; |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 203 | case BTAV_A2DP_CODEC_INDEX_SOURCE_AAC: |
| 204 | supported = true; |
| 205 | break; |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 206 | case BTAV_A2DP_CODEC_INDEX_SOURCE_APTX: |
| 207 | // Codec aptX is supported only if the device has the corresponding |
| 208 | // shared library installed. |
| 209 | supported = has_shared_library(APTX_ENCODER_LIB_NAME); |
| 210 | break; |
| 211 | case BTAV_A2DP_CODEC_INDEX_SOURCE_APTX_HD: |
| 212 | // Codec aptX-HD is supported only if the device has the corresponding |
| 213 | // shared library installed. |
| 214 | supported = has_shared_library(APTX_HD_ENCODER_LIB_NAME); |
| 215 | break; |
| 216 | case BTAV_A2DP_CODEC_INDEX_SOURCE_LDAC: |
| 217 | // Codec LDAC is supported only if the device has the corresponding |
| 218 | // shared library installed. |
| 219 | supported = has_shared_library(LDAC_ENCODER_LIB_NAME); |
| 220 | break; |
| 221 | case BTAV_A2DP_CODEC_INDEX_SINK_SBC: |
| 222 | supported = true; |
| 223 | break; |
Bailey Forrest | 7e2ab69 | 2017-06-16 15:38:03 -0700 | [diff] [blame] | 224 | case BTAV_A2DP_CODEC_INDEX_SINK_AAC: |
| 225 | supported = true; |
| 226 | break; |
Chisato Kenmochi | f57c428 | 2018-08-10 20:44:05 +0900 | [diff] [blame] | 227 | case BTAV_A2DP_CODEC_INDEX_SINK_LDAC: |
| 228 | // Codec LDAC is supported only if the device has the corresponding |
| 229 | // shared library installed. |
| 230 | supported = has_shared_library(LDAC_DECODER_LIB_NAME); |
| 231 | break; |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 232 | case BTAV_A2DP_CODEC_INDEX_MAX: |
| 233 | // Needed to avoid using "default:" case so we can capture when |
| 234 | // a new codec is added, and it can be included here. |
| 235 | break; |
| 236 | } |
| 237 | |
| 238 | if (supported) { |
| 239 | supported_codecs_.insert(codec_index); |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | bool has_codec_support(btav_a2dp_codec_index_t codec_index) { |
| 245 | return supported_codecs_.find(codec_index) != supported_codecs_.end(); |
| 246 | } |
| 247 | |
| 248 | private: |
| 249 | std::set<btav_a2dp_codec_index_t> supported_codecs_; |
| 250 | }; |
| 251 | |
| 252 | class A2dpCodecConfigTest : public StackA2dpTest {}; |
| 253 | |
| 254 | TEST_F(StackA2dpTest, test_a2dp_bits_set) { |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 255 | EXPECT_TRUE(A2DP_BitsSet(0x0) == A2DP_SET_ZERO_BIT); |
| 256 | EXPECT_TRUE(A2DP_BitsSet(0x1) == A2DP_SET_ONE_BIT); |
| 257 | EXPECT_TRUE(A2DP_BitsSet(0x2) == A2DP_SET_ONE_BIT); |
| 258 | EXPECT_TRUE(A2DP_BitsSet(0x3) == A2DP_SET_MULTL_BIT); |
| 259 | EXPECT_TRUE(A2DP_BitsSet(0x7f) == A2DP_SET_MULTL_BIT); |
| 260 | EXPECT_TRUE(A2DP_BitsSet(0x80) == A2DP_SET_ONE_BIT); |
| 261 | EXPECT_TRUE(A2DP_BitsSet(0x81) == A2DP_SET_MULTL_BIT); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 262 | EXPECT_TRUE(A2DP_BitsSet(0xc0) == A2DP_SET_MULTL_BIT); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 263 | EXPECT_TRUE(A2DP_BitsSet(0xff) == A2DP_SET_MULTL_BIT); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 264 | EXPECT_TRUE(A2DP_BitsSet(0x8000) == A2DP_SET_ONE_BIT); |
| 265 | EXPECT_TRUE(A2DP_BitsSet(0x8001) == A2DP_SET_MULTL_BIT); |
| 266 | EXPECT_TRUE(A2DP_BitsSet(0xc000) == A2DP_SET_MULTL_BIT); |
| 267 | EXPECT_TRUE(A2DP_BitsSet(0xffff) == A2DP_SET_MULTL_BIT); |
| 268 | EXPECT_TRUE(A2DP_BitsSet(0x80000) == A2DP_SET_ONE_BIT); |
| 269 | EXPECT_TRUE(A2DP_BitsSet(0x80001) == A2DP_SET_MULTL_BIT); |
| 270 | EXPECT_TRUE(A2DP_BitsSet(0xc0000) == A2DP_SET_MULTL_BIT); |
| 271 | EXPECT_TRUE(A2DP_BitsSet(0xfffff) == A2DP_SET_MULTL_BIT); |
| 272 | EXPECT_TRUE(A2DP_BitsSet(0x80000000) == A2DP_SET_ONE_BIT); |
| 273 | EXPECT_TRUE(A2DP_BitsSet(0x80000001) == A2DP_SET_MULTL_BIT); |
| 274 | EXPECT_TRUE(A2DP_BitsSet(0xc0000000) == A2DP_SET_MULTL_BIT); |
| 275 | EXPECT_TRUE(A2DP_BitsSet(0xffffffff) == A2DP_SET_MULTL_BIT); |
| 276 | EXPECT_TRUE(A2DP_BitsSet(0x8000000000000000) == A2DP_SET_ONE_BIT); |
| 277 | EXPECT_TRUE(A2DP_BitsSet(0x8000000000000001) == A2DP_SET_MULTL_BIT); |
| 278 | EXPECT_TRUE(A2DP_BitsSet(0xc000000000000000) == A2DP_SET_MULTL_BIT); |
| 279 | EXPECT_TRUE(A2DP_BitsSet(0xffffffffffffffff) == A2DP_SET_MULTL_BIT); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 280 | } |
| 281 | |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 282 | TEST_F(StackA2dpTest, test_a2dp_is_codec_valid_sbc) { |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 283 | EXPECT_TRUE(A2DP_IsSourceCodecValid(codec_info_sbc)); |
koh.changseok | 444ea2c | 2017-07-04 02:37:42 +0900 | [diff] [blame] | 284 | EXPECT_TRUE(A2DP_IsSourceCodecValid(codec_info_sbc_capability)); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 285 | EXPECT_TRUE(A2DP_IsPeerSourceCodecValid(codec_info_sbc)); |
koh.changseok | 444ea2c | 2017-07-04 02:37:42 +0900 | [diff] [blame] | 286 | EXPECT_TRUE(A2DP_IsPeerSourceCodecValid(codec_info_sbc_capability)); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 287 | |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 288 | EXPECT_TRUE(A2DP_IsSinkCodecValid(codec_info_sbc_sink_capability)); |
| 289 | EXPECT_TRUE(A2DP_IsPeerSinkCodecValid(codec_info_sbc_sink_capability)); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 290 | |
| 291 | EXPECT_FALSE(A2DP_IsSourceCodecValid(codec_info_non_a2dp)); |
| 292 | EXPECT_FALSE(A2DP_IsSinkCodecValid(codec_info_non_a2dp)); |
| 293 | EXPECT_FALSE(A2DP_IsPeerSourceCodecValid(codec_info_non_a2dp)); |
| 294 | EXPECT_FALSE(A2DP_IsPeerSinkCodecValid(codec_info_non_a2dp)); |
| 295 | |
| 296 | // Test with invalid SBC codecs |
| 297 | uint8_t codec_info_sbc_invalid[AVDT_CODEC_SIZE]; |
| 298 | memset(codec_info_sbc_invalid, 0, sizeof(codec_info_sbc_invalid)); |
| 299 | EXPECT_FALSE(A2DP_IsSourceCodecValid(codec_info_sbc_invalid)); |
| 300 | EXPECT_FALSE(A2DP_IsSinkCodecValid(codec_info_sbc_invalid)); |
| 301 | EXPECT_FALSE(A2DP_IsPeerSourceCodecValid(codec_info_sbc_invalid)); |
| 302 | EXPECT_FALSE(A2DP_IsPeerSinkCodecValid(codec_info_sbc_invalid)); |
| 303 | |
| 304 | memcpy(codec_info_sbc_invalid, codec_info_sbc, sizeof(codec_info_sbc)); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 305 | codec_info_sbc_invalid[0] = 0; // Corrupt the Length field |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 306 | EXPECT_FALSE(A2DP_IsSourceCodecValid(codec_info_sbc_invalid)); |
| 307 | EXPECT_FALSE(A2DP_IsSinkCodecValid(codec_info_sbc_invalid)); |
| 308 | EXPECT_FALSE(A2DP_IsPeerSourceCodecValid(codec_info_sbc_invalid)); |
| 309 | EXPECT_FALSE(A2DP_IsPeerSinkCodecValid(codec_info_sbc_invalid)); |
| 310 | |
| 311 | memcpy(codec_info_sbc_invalid, codec_info_sbc, sizeof(codec_info_sbc)); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 312 | codec_info_sbc_invalid[1] = 0xff; // Corrupt the Media Type field |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 313 | EXPECT_FALSE(A2DP_IsSourceCodecValid(codec_info_sbc_invalid)); |
| 314 | EXPECT_FALSE(A2DP_IsSinkCodecValid(codec_info_sbc_invalid)); |
| 315 | EXPECT_FALSE(A2DP_IsPeerSourceCodecValid(codec_info_sbc_invalid)); |
| 316 | EXPECT_FALSE(A2DP_IsPeerSinkCodecValid(codec_info_sbc_invalid)); |
| 317 | } |
| 318 | |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 319 | TEST_F(StackA2dpTest, test_a2dp_is_codec_valid_aac) { |
| 320 | EXPECT_TRUE(A2DP_IsSourceCodecValid(codec_info_aac)); |
koh.changseok | 444ea2c | 2017-07-04 02:37:42 +0900 | [diff] [blame] | 321 | EXPECT_TRUE(A2DP_IsSourceCodecValid(codec_info_aac_capability)); |
Bailey Forrest | 7e2ab69 | 2017-06-16 15:38:03 -0700 | [diff] [blame] | 322 | EXPECT_TRUE(A2DP_IsPeerSourceCodecValid(codec_info_aac)); |
| 323 | EXPECT_TRUE(A2DP_IsPeerSourceCodecValid(codec_info_aac_capability)); |
koh.changseok | 444ea2c | 2017-07-04 02:37:42 +0900 | [diff] [blame] | 324 | |
Bailey Forrest | 7e2ab69 | 2017-06-16 15:38:03 -0700 | [diff] [blame] | 325 | EXPECT_TRUE(A2DP_IsSinkCodecValid(codec_info_aac_sink_capability)); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 326 | EXPECT_TRUE(A2DP_IsPeerSinkCodecValid(codec_info_aac_sink_capability)); |
| 327 | |
| 328 | // Test with invalid AAC codecs |
| 329 | uint8_t codec_info_aac_invalid[AVDT_CODEC_SIZE]; |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 330 | memcpy(codec_info_aac_invalid, codec_info_aac, sizeof(codec_info_aac)); |
| 331 | codec_info_aac_invalid[0] = 0; // Corrupt the Length field |
| 332 | EXPECT_FALSE(A2DP_IsSourceCodecValid(codec_info_aac_invalid)); |
koh.changseok | 444ea2c | 2017-07-04 02:37:42 +0900 | [diff] [blame] | 333 | EXPECT_FALSE(A2DP_IsSinkCodecValid(codec_info_aac_invalid)); |
| 334 | EXPECT_FALSE(A2DP_IsPeerSourceCodecValid(codec_info_aac_invalid)); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 335 | EXPECT_FALSE(A2DP_IsPeerSinkCodecValid(codec_info_aac_invalid)); |
| 336 | |
| 337 | memcpy(codec_info_aac_invalid, codec_info_aac, sizeof(codec_info_aac)); |
| 338 | codec_info_aac_invalid[1] = 0xff; // Corrupt the Media Type field |
| 339 | EXPECT_FALSE(A2DP_IsSourceCodecValid(codec_info_aac_invalid)); |
koh.changseok | 444ea2c | 2017-07-04 02:37:42 +0900 | [diff] [blame] | 340 | EXPECT_FALSE(A2DP_IsSinkCodecValid(codec_info_aac_invalid)); |
| 341 | EXPECT_FALSE(A2DP_IsPeerSourceCodecValid(codec_info_aac_invalid)); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 342 | EXPECT_FALSE(A2DP_IsPeerSinkCodecValid(codec_info_aac_invalid)); |
| 343 | } |
| 344 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 345 | TEST_F(StackA2dpTest, test_a2dp_get_codec_type) { |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 346 | tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(codec_info_sbc); |
| 347 | EXPECT_EQ(codec_type, A2DP_MEDIA_CT_SBC); |
| 348 | |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 349 | codec_type = A2DP_GetCodecType(codec_info_aac); |
| 350 | EXPECT_EQ(codec_type, A2DP_MEDIA_CT_AAC); |
| 351 | |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 352 | codec_type = A2DP_GetCodecType(codec_info_non_a2dp); |
| 353 | EXPECT_EQ(codec_type, A2DP_MEDIA_CT_NON_A2DP); |
| 354 | } |
| 355 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 356 | TEST_F(StackA2dpTest, test_a2dp_is_sink_codec_supported) { |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 357 | EXPECT_TRUE(A2DP_IsSinkCodecSupported(codec_info_sbc)); |
koh.changseok | 444ea2c | 2017-07-04 02:37:42 +0900 | [diff] [blame] | 358 | EXPECT_FALSE(A2DP_IsSinkCodecSupported(codec_info_sbc_capability)); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 359 | EXPECT_FALSE(A2DP_IsSinkCodecSupported(codec_info_sbc_sink_capability)); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 360 | |
Bailey Forrest | 7e2ab69 | 2017-06-16 15:38:03 -0700 | [diff] [blame] | 361 | EXPECT_TRUE(A2DP_IsSinkCodecSupported(codec_info_aac)); |
| 362 | // NOTE: The test below should be EXPECT_FALSE. |
| 363 | // However, codec_info_aac_capability is practically same as codec_info_aac, |
| 364 | // therefore we cannot differentiate it as a capability. |
| 365 | EXPECT_TRUE(A2DP_IsSinkCodecSupported(codec_info_aac_capability)); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 366 | EXPECT_FALSE(A2DP_IsSinkCodecSupported(codec_info_aac_sink_capability)); |
| 367 | |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 368 | EXPECT_FALSE(A2DP_IsSinkCodecSupported(codec_info_non_a2dp)); |
| 369 | } |
| 370 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 371 | TEST_F(StackA2dpTest, test_a2dp_is_peer_source_codec_supported) { |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 372 | EXPECT_TRUE(A2DP_IsPeerSourceCodecSupported(codec_info_sbc)); |
koh.changseok | 444ea2c | 2017-07-04 02:37:42 +0900 | [diff] [blame] | 373 | EXPECT_TRUE(A2DP_IsPeerSourceCodecSupported(codec_info_sbc_capability)); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 374 | EXPECT_TRUE(A2DP_IsPeerSourceCodecSupported(codec_info_sbc_sink_capability)); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 375 | |
Bailey Forrest | 7e2ab69 | 2017-06-16 15:38:03 -0700 | [diff] [blame] | 376 | EXPECT_TRUE(A2DP_IsPeerSourceCodecSupported(codec_info_aac)); |
| 377 | EXPECT_TRUE(A2DP_IsPeerSourceCodecSupported(codec_info_aac_capability)); |
| 378 | EXPECT_TRUE(A2DP_IsPeerSourceCodecSupported(codec_info_aac_sink_capability)); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 379 | |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 380 | EXPECT_FALSE(A2DP_IsPeerSourceCodecSupported(codec_info_non_a2dp)); |
| 381 | } |
| 382 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 383 | TEST_F(StackA2dpTest, test_init_default_codec) { |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 384 | uint8_t codec_info_result[AVDT_CODEC_SIZE]; |
| 385 | |
| 386 | memset(codec_info_result, 0, sizeof(codec_info_result)); |
| 387 | A2DP_InitDefaultCodec(codec_info_result); |
| 388 | |
| 389 | // Compare the result codec with the local test codec info |
| 390 | for (size_t i = 0; i < codec_info_sbc[0] + 1; i++) { |
| 391 | EXPECT_EQ(codec_info_result[i], codec_info_sbc[i]); |
| 392 | } |
| 393 | } |
| 394 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 395 | TEST_F(StackA2dpTest, test_a2dp_uses_rtp_header) { |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 396 | EXPECT_TRUE(A2DP_UsesRtpHeader(true, codec_info_sbc)); |
| 397 | EXPECT_TRUE(A2DP_UsesRtpHeader(false, codec_info_sbc)); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 398 | |
| 399 | EXPECT_TRUE(A2DP_UsesRtpHeader(true, codec_info_aac)); |
| 400 | EXPECT_TRUE(A2DP_UsesRtpHeader(false, codec_info_aac)); |
| 401 | |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 402 | EXPECT_TRUE(A2DP_UsesRtpHeader(true, codec_info_non_a2dp)); |
| 403 | EXPECT_TRUE(A2DP_UsesRtpHeader(false, codec_info_non_a2dp)); |
| 404 | } |
| 405 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 406 | TEST_F(StackA2dpTest, test_a2dp_get_media_type) { |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 407 | uint8_t codec_info_test[AVDT_CODEC_SIZE]; |
| 408 | |
| 409 | EXPECT_EQ(A2DP_GetMediaType(codec_info_sbc), AVDT_MEDIA_TYPE_AUDIO); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 410 | EXPECT_EQ(A2DP_GetMediaType(codec_info_aac), AVDT_MEDIA_TYPE_AUDIO); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 411 | EXPECT_EQ(A2DP_GetMediaType(codec_info_non_a2dp), AVDT_MEDIA_TYPE_AUDIO); |
| 412 | |
| 413 | // Prepare dummy codec info for video and for multimedia |
| 414 | memset(codec_info_test, 0, sizeof(codec_info_test)); |
| 415 | codec_info_test[0] = sizeof(codec_info_test); |
| 416 | codec_info_test[1] = 0x01 << 4; |
| 417 | EXPECT_EQ(A2DP_GetMediaType(codec_info_test), AVDT_MEDIA_TYPE_VIDEO); |
| 418 | codec_info_test[1] = 0x02 << 4; |
| 419 | EXPECT_EQ(A2DP_GetMediaType(codec_info_test), AVDT_MEDIA_TYPE_MULTI); |
| 420 | } |
| 421 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 422 | TEST_F(StackA2dpTest, test_a2dp_codec_name) { |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 423 | uint8_t codec_info_test[AVDT_CODEC_SIZE]; |
| 424 | |
| 425 | // Explicit tests for known codecs |
| 426 | EXPECT_STREQ(A2DP_CodecName(codec_info_sbc), "SBC"); |
koh.changseok | 444ea2c | 2017-07-04 02:37:42 +0900 | [diff] [blame] | 427 | EXPECT_STREQ(A2DP_CodecName(codec_info_sbc_capability), "SBC"); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 428 | EXPECT_STREQ(A2DP_CodecName(codec_info_sbc_sink_capability), "SBC"); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 429 | EXPECT_STREQ(A2DP_CodecName(codec_info_aac), "AAC"); |
| 430 | EXPECT_STREQ(A2DP_CodecName(codec_info_aac_capability), "AAC"); |
| 431 | EXPECT_STREQ(A2DP_CodecName(codec_info_aac_sink_capability), "AAC"); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 432 | EXPECT_STREQ(A2DP_CodecName(codec_info_non_a2dp), "UNKNOWN VENDOR CODEC"); |
| 433 | |
| 434 | // Test all unknown codecs |
| 435 | memcpy(codec_info_test, codec_info_sbc, sizeof(codec_info_sbc)); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 436 | for (uint8_t codec_type = A2DP_MEDIA_CT_AAC + 1; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 437 | codec_type < A2DP_MEDIA_CT_NON_A2DP; codec_type++) { |
| 438 | codec_info_test[2] = codec_type; // Unknown codec type |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 439 | EXPECT_STREQ(A2DP_CodecName(codec_info_test), "UNKNOWN CODEC"); |
| 440 | } |
| 441 | } |
| 442 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 443 | TEST_F(StackA2dpTest, test_a2dp_vendor) { |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 444 | EXPECT_EQ(A2DP_VendorCodecGetVendorId(codec_info_non_a2dp), |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 445 | (uint32_t)0x00000403); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 446 | EXPECT_EQ(A2DP_VendorCodecGetCodecId(codec_info_non_a2dp), (uint16_t)0x0807); |
| 447 | EXPECT_TRUE(A2DP_VendorUsesRtpHeader(true, codec_info_non_a2dp)); |
| 448 | EXPECT_TRUE(A2DP_VendorUsesRtpHeader(false, codec_info_non_a2dp)); |
| 449 | } |
| 450 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 451 | TEST_F(StackA2dpTest, test_a2dp_codec_type_equals) { |
koh.changseok | 444ea2c | 2017-07-04 02:37:42 +0900 | [diff] [blame] | 452 | EXPECT_TRUE(A2DP_CodecTypeEquals(codec_info_sbc, codec_info_sbc_capability)); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 453 | EXPECT_TRUE( |
| 454 | A2DP_CodecTypeEquals(codec_info_sbc, codec_info_sbc_sink_capability)); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 455 | EXPECT_TRUE(A2DP_CodecTypeEquals(codec_info_aac, codec_info_aac_capability)); |
| 456 | EXPECT_TRUE( |
| 457 | A2DP_CodecTypeEquals(codec_info_aac, codec_info_aac_sink_capability)); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 458 | EXPECT_TRUE( |
| 459 | A2DP_CodecTypeEquals(codec_info_non_a2dp, codec_info_non_a2dp_dummy)); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 460 | EXPECT_FALSE(A2DP_CodecTypeEquals(codec_info_sbc, codec_info_non_a2dp)); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 461 | EXPECT_FALSE(A2DP_CodecTypeEquals(codec_info_aac, codec_info_non_a2dp)); |
| 462 | EXPECT_FALSE(A2DP_CodecTypeEquals(codec_info_sbc, codec_info_aac)); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 465 | TEST_F(StackA2dpTest, test_a2dp_codec_equals) { |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 466 | uint8_t codec_info_sbc_test[AVDT_CODEC_SIZE]; |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 467 | uint8_t codec_info_aac_test[AVDT_CODEC_SIZE]; |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 468 | uint8_t codec_info_non_a2dp_test[AVDT_CODEC_SIZE]; |
| 469 | |
| 470 | // Test two identical SBC codecs |
| 471 | memset(codec_info_sbc_test, 0xAB, sizeof(codec_info_sbc_test)); |
| 472 | memcpy(codec_info_sbc_test, codec_info_sbc, sizeof(codec_info_sbc)); |
| 473 | EXPECT_TRUE(A2DP_CodecEquals(codec_info_sbc, codec_info_sbc_test)); |
| 474 | |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 475 | // Test two identical AAC codecs |
| 476 | memset(codec_info_aac_test, 0xAB, sizeof(codec_info_aac_test)); |
| 477 | memcpy(codec_info_aac_test, codec_info_aac, sizeof(codec_info_aac)); |
| 478 | EXPECT_TRUE(A2DP_CodecEquals(codec_info_aac, codec_info_aac_test)); |
| 479 | |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 480 | // Test two identical non-A2DP codecs that are not recognized |
| 481 | memset(codec_info_non_a2dp_test, 0xAB, sizeof(codec_info_non_a2dp_test)); |
| 482 | memcpy(codec_info_non_a2dp_test, codec_info_non_a2dp, |
| 483 | sizeof(codec_info_non_a2dp)); |
| 484 | EXPECT_FALSE(A2DP_CodecEquals(codec_info_non_a2dp, codec_info_non_a2dp_test)); |
| 485 | |
| 486 | // Test two codecs that have different types |
| 487 | EXPECT_FALSE(A2DP_CodecEquals(codec_info_sbc, codec_info_non_a2dp)); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 488 | EXPECT_FALSE(A2DP_CodecEquals(codec_info_sbc, codec_info_aac)); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 489 | |
| 490 | // Test two SBC codecs that are slightly different |
| 491 | memset(codec_info_sbc_test, 0xAB, sizeof(codec_info_sbc_test)); |
| 492 | memcpy(codec_info_sbc_test, codec_info_sbc, sizeof(codec_info_sbc)); |
| 493 | codec_info_sbc_test[5] = codec_info_sbc[5] + 1; |
| 494 | EXPECT_FALSE(A2DP_CodecEquals(codec_info_sbc, codec_info_sbc_test)); |
| 495 | codec_info_sbc_test[5] = codec_info_sbc[5]; |
| 496 | codec_info_sbc_test[6] = codec_info_sbc[6] + 1; |
| 497 | EXPECT_FALSE(A2DP_CodecEquals(codec_info_sbc, codec_info_sbc_test)); |
| 498 | |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 499 | // Test two AAC codecs that are slightly different |
| 500 | memset(codec_info_aac_test, 0xAB, sizeof(codec_info_aac_test)); |
| 501 | memcpy(codec_info_aac_test, codec_info_aac, sizeof(codec_info_aac)); |
| 502 | codec_info_aac_test[7] = codec_info_aac[7] + 1; |
| 503 | EXPECT_FALSE(A2DP_CodecEquals(codec_info_aac, codec_info_aac_test)); |
| 504 | codec_info_aac_test[7] = codec_info_aac[7]; |
| 505 | codec_info_aac_test[8] = codec_info_aac[8] + 1; |
| 506 | EXPECT_FALSE(A2DP_CodecEquals(codec_info_aac, codec_info_aac_test)); |
| 507 | |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 508 | // Test two SBC codecs that are identical, but with different dummy |
| 509 | // trailer data. |
| 510 | memset(codec_info_sbc_test, 0xAB, sizeof(codec_info_sbc_test)); |
| 511 | memcpy(codec_info_sbc_test, codec_info_sbc, sizeof(codec_info_sbc)); |
| 512 | codec_info_sbc_test[7] = codec_info_sbc[7] + 1; |
| 513 | EXPECT_TRUE(A2DP_CodecEquals(codec_info_sbc, codec_info_sbc_test)); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 514 | |
| 515 | // Test two AAC codecs that are identical, but with different dummy |
| 516 | // trailer data. |
| 517 | memset(codec_info_aac_test, 0xAB, sizeof(codec_info_aac_test)); |
| 518 | memcpy(codec_info_aac_test, codec_info_aac, sizeof(codec_info_aac)); |
| 519 | codec_info_aac_test[9] = codec_info_aac[9] + 1; |
| 520 | EXPECT_TRUE(A2DP_CodecEquals(codec_info_aac, codec_info_aac_test)); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 523 | TEST_F(StackA2dpTest, test_a2dp_get_track_sample_rate) { |
Pavlin Radoslavov | cd02ce9 | 2016-11-04 17:18:51 -0700 | [diff] [blame] | 524 | EXPECT_EQ(A2DP_GetTrackSampleRate(codec_info_sbc), 44100); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 525 | EXPECT_EQ(A2DP_GetTrackSampleRate(codec_info_aac), 44100); |
Pavlin Radoslavov | cd02ce9 | 2016-11-04 17:18:51 -0700 | [diff] [blame] | 526 | EXPECT_EQ(A2DP_GetTrackSampleRate(codec_info_non_a2dp), -1); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 529 | TEST_F(StackA2dpTest, test_a2dp_get_track_channel_count) { |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 530 | EXPECT_EQ(A2DP_GetTrackChannelCount(codec_info_sbc), 2); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 531 | EXPECT_EQ(A2DP_GetTrackChannelCount(codec_info_aac), 2); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 532 | EXPECT_EQ(A2DP_GetTrackChannelCount(codec_info_non_a2dp), -1); |
| 533 | } |
| 534 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 535 | TEST_F(StackA2dpTest, test_a2dp_get_number_of_subbands_sbc) { |
Pavlin Radoslavov | cd02ce9 | 2016-11-04 17:18:51 -0700 | [diff] [blame] | 536 | EXPECT_EQ(A2DP_GetNumberOfSubbandsSbc(codec_info_sbc), 8); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 537 | EXPECT_EQ(A2DP_GetNumberOfSubbandsSbc(codec_info_aac), -1); |
Pavlin Radoslavov | cd02ce9 | 2016-11-04 17:18:51 -0700 | [diff] [blame] | 538 | EXPECT_EQ(A2DP_GetNumberOfSubbandsSbc(codec_info_non_a2dp), -1); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 541 | TEST_F(StackA2dpTest, test_a2dp_get_number_of_blocks_sbc) { |
Pavlin Radoslavov | cd02ce9 | 2016-11-04 17:18:51 -0700 | [diff] [blame] | 542 | EXPECT_EQ(A2DP_GetNumberOfBlocksSbc(codec_info_sbc), 16); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 543 | EXPECT_EQ(A2DP_GetNumberOfBlocksSbc(codec_info_aac), -1); |
Pavlin Radoslavov | cd02ce9 | 2016-11-04 17:18:51 -0700 | [diff] [blame] | 544 | EXPECT_EQ(A2DP_GetNumberOfBlocksSbc(codec_info_non_a2dp), -1); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 547 | TEST_F(StackA2dpTest, test_a2dp_get_allocation_method_code_sbc) { |
Pavlin Radoslavov | cd02ce9 | 2016-11-04 17:18:51 -0700 | [diff] [blame] | 548 | EXPECT_EQ(A2DP_GetAllocationMethodCodeSbc(codec_info_sbc), 0); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 549 | EXPECT_EQ(A2DP_GetAllocationMethodCodeSbc(codec_info_aac), -1); |
Pavlin Radoslavov | cd02ce9 | 2016-11-04 17:18:51 -0700 | [diff] [blame] | 550 | EXPECT_EQ(A2DP_GetAllocationMethodCodeSbc(codec_info_non_a2dp), -1); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 551 | } |
| 552 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 553 | TEST_F(StackA2dpTest, test_a2dp_get_channel_mode_code_sbc) { |
Pavlin Radoslavov | cd02ce9 | 2016-11-04 17:18:51 -0700 | [diff] [blame] | 554 | EXPECT_EQ(A2DP_GetChannelModeCodeSbc(codec_info_sbc), 3); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 555 | EXPECT_EQ(A2DP_GetChannelModeCodeSbc(codec_info_aac), -1); |
Pavlin Radoslavov | cd02ce9 | 2016-11-04 17:18:51 -0700 | [diff] [blame] | 556 | EXPECT_EQ(A2DP_GetChannelModeCodeSbc(codec_info_non_a2dp), -1); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 559 | TEST_F(StackA2dpTest, test_a2dp_get_sampling_frequency_code_sbc) { |
Pavlin Radoslavov | cd02ce9 | 2016-11-04 17:18:51 -0700 | [diff] [blame] | 560 | EXPECT_EQ(A2DP_GetSamplingFrequencyCodeSbc(codec_info_sbc), 2); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 561 | EXPECT_EQ(A2DP_GetSamplingFrequencyCodeSbc(codec_info_aac), -1); |
Pavlin Radoslavov | cd02ce9 | 2016-11-04 17:18:51 -0700 | [diff] [blame] | 562 | EXPECT_EQ(A2DP_GetSamplingFrequencyCodeSbc(codec_info_non_a2dp), -1); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 565 | TEST_F(StackA2dpTest, test_a2dp_get_min_bitpool_sbc) { |
Pavlin Radoslavov | cd02ce9 | 2016-11-04 17:18:51 -0700 | [diff] [blame] | 566 | EXPECT_EQ(A2DP_GetMinBitpoolSbc(codec_info_sbc), 2); |
koh.changseok | 444ea2c | 2017-07-04 02:37:42 +0900 | [diff] [blame] | 567 | EXPECT_EQ(A2DP_GetMinBitpoolSbc(codec_info_sbc_capability), 2); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 568 | EXPECT_EQ(A2DP_GetMinBitpoolSbc(codec_info_sbc_sink_capability), 2); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 569 | EXPECT_EQ(A2DP_GetMinBitpoolSbc(codec_info_aac), -1); |
Pavlin Radoslavov | cd02ce9 | 2016-11-04 17:18:51 -0700 | [diff] [blame] | 570 | EXPECT_EQ(A2DP_GetMinBitpoolSbc(codec_info_non_a2dp), -1); |
| 571 | } |
| 572 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 573 | TEST_F(StackA2dpTest, test_a2dp_get_max_bitpool_sbc) { |
Pavlin Radoslavov | cd02ce9 | 2016-11-04 17:18:51 -0700 | [diff] [blame] | 574 | EXPECT_EQ(A2DP_GetMaxBitpoolSbc(codec_info_sbc), 53); |
koh.changseok | 444ea2c | 2017-07-04 02:37:42 +0900 | [diff] [blame] | 575 | EXPECT_EQ(A2DP_GetMaxBitpoolSbc(codec_info_sbc_capability), 53); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 576 | EXPECT_EQ(A2DP_GetMaxBitpoolSbc(codec_info_sbc_sink_capability), 53); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 577 | EXPECT_EQ(A2DP_GetMaxBitpoolSbc(codec_info_aac), -1); |
Pavlin Radoslavov | cd02ce9 | 2016-11-04 17:18:51 -0700 | [diff] [blame] | 578 | EXPECT_EQ(A2DP_GetMaxBitpoolSbc(codec_info_non_a2dp), -1); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 581 | TEST_F(StackA2dpTest, test_a2dp_get_sink_track_channel_type) { |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 582 | EXPECT_EQ(A2DP_GetSinkTrackChannelType(codec_info_sbc), 3); |
Bailey Forrest | 7e2ab69 | 2017-06-16 15:38:03 -0700 | [diff] [blame] | 583 | EXPECT_EQ(A2DP_GetSinkTrackChannelType(codec_info_aac), 3); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 584 | EXPECT_EQ(A2DP_GetSinkTrackChannelType(codec_info_non_a2dp), -1); |
| 585 | } |
| 586 | |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 587 | TEST_F(StackA2dpTest, test_a2dp_get_object_type_code_aac) { |
| 588 | EXPECT_EQ(A2DP_GetObjectTypeCodeAac(codec_info_sbc), -1); |
| 589 | EXPECT_EQ(A2DP_GetObjectTypeCodeAac(codec_info_aac), 0x80); |
| 590 | EXPECT_EQ(A2DP_GetObjectTypeCodeAac(codec_info_non_a2dp), -1); |
| 591 | } |
| 592 | |
| 593 | TEST_F(StackA2dpTest, test_a2dp_get_channel_mode_code_aac) { |
| 594 | EXPECT_EQ(A2DP_GetChannelModeCodeAac(codec_info_sbc), -1); |
| 595 | EXPECT_EQ(A2DP_GetChannelModeCodeAac(codec_info_aac), 0x04); |
| 596 | EXPECT_EQ(A2DP_GetChannelModeCodeAac(codec_info_non_a2dp), -1); |
| 597 | } |
| 598 | |
| 599 | TEST_F(StackA2dpTest, test_a2dp_get_variable_bit_rate_support_aac) { |
| 600 | EXPECT_EQ(A2DP_GetVariableBitRateSupportAac(codec_info_sbc), -1); |
| 601 | EXPECT_EQ(A2DP_GetVariableBitRateSupportAac(codec_info_aac), 0); |
| 602 | EXPECT_EQ(A2DP_GetVariableBitRateSupportAac(codec_info_non_a2dp), -1); |
| 603 | } |
| 604 | |
| 605 | TEST_F(StackA2dpTest, test_a2dp_get_bit_rate_aac) { |
| 606 | EXPECT_EQ(A2DP_GetBitRateAac(codec_info_sbc), -1); |
| 607 | EXPECT_EQ(A2DP_GetBitRateAac(codec_info_aac), 320000); |
| 608 | EXPECT_EQ(A2DP_GetBitRateAac(codec_info_non_a2dp), -1); |
| 609 | } |
| 610 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 611 | TEST_F(StackA2dpTest, test_a2dp_get_packet_timestamp) { |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 612 | uint8_t a2dp_data[1000]; |
| 613 | uint32_t timestamp; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 614 | uint32_t* p_ts = reinterpret_cast<uint32_t*>(a2dp_data); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 615 | |
| 616 | memset(a2dp_data, 0xAB, sizeof(a2dp_data)); |
| 617 | *p_ts = 0x12345678; |
| 618 | timestamp = 0xFFFFFFFF; |
| 619 | EXPECT_TRUE(A2DP_GetPacketTimestamp(codec_info_sbc, a2dp_data, ×tamp)); |
| 620 | EXPECT_EQ(timestamp, static_cast<uint32_t>(0x12345678)); |
| 621 | |
| 622 | memset(a2dp_data, 0xAB, sizeof(a2dp_data)); |
| 623 | *p_ts = 0x12345678; |
| 624 | timestamp = 0xFFFFFFFF; |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 625 | EXPECT_TRUE(A2DP_GetPacketTimestamp(codec_info_aac, a2dp_data, ×tamp)); |
| 626 | EXPECT_EQ(timestamp, static_cast<uint32_t>(0x12345678)); |
| 627 | |
| 628 | memset(a2dp_data, 0xAB, sizeof(a2dp_data)); |
| 629 | *p_ts = 0x12345678; |
| 630 | timestamp = 0xFFFFFFFF; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 631 | EXPECT_FALSE( |
| 632 | A2DP_GetPacketTimestamp(codec_info_non_a2dp, a2dp_data, ×tamp)); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 635 | TEST_F(StackA2dpTest, test_a2dp_build_codec_header) { |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 636 | uint8_t a2dp_data[1000]; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 637 | BT_HDR* p_buf = reinterpret_cast<BT_HDR*>(a2dp_data); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 638 | const uint16_t BT_HDR_LEN = 500; |
| 639 | const uint16_t BT_HDR_OFFSET = 50; |
| 640 | const uint8_t FRAMES_PER_PACKET = 0xCD; |
| 641 | |
| 642 | memset(a2dp_data, 0xAB, sizeof(a2dp_data)); |
| 643 | p_buf->len = BT_HDR_LEN; |
| 644 | p_buf->offset = BT_HDR_OFFSET; |
| 645 | EXPECT_TRUE(A2DP_BuildCodecHeader(codec_info_sbc, p_buf, FRAMES_PER_PACKET)); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 646 | EXPECT_EQ(p_buf->offset + 1, |
| 647 | BT_HDR_OFFSET); // Modified by A2DP_SBC_MPL_HDR_LEN |
| 648 | EXPECT_EQ(p_buf->len - 1, BT_HDR_LEN); // Modified by A2DP_SBC_MPL_HDR_LEN |
| 649 | const uint8_t* p = |
| 650 | reinterpret_cast<const uint8_t*>(p_buf + 1) + p_buf->offset; |
| 651 | EXPECT_EQ( |
| 652 | *p, static_cast<uint8_t>(0x0D)); // 0xCD masked with A2DP_SBC_HDR_NUM_MSK |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 653 | |
| 654 | memset(a2dp_data, 0xAB, sizeof(a2dp_data)); |
| 655 | p_buf->len = BT_HDR_LEN; |
| 656 | p_buf->offset = BT_HDR_OFFSET; |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 657 | EXPECT_TRUE(A2DP_BuildCodecHeader(codec_info_aac, p_buf, FRAMES_PER_PACKET)); |
| 658 | |
| 659 | memset(a2dp_data, 0xAB, sizeof(a2dp_data)); |
| 660 | p_buf->len = BT_HDR_LEN; |
| 661 | p_buf->offset = BT_HDR_OFFSET; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 662 | EXPECT_FALSE( |
| 663 | A2DP_BuildCodecHeader(codec_info_non_a2dp, p_buf, FRAMES_PER_PACKET)); |
Pavlin Radoslavov | f66f4e9 | 2016-10-14 15:14:37 -0700 | [diff] [blame] | 664 | } |
Pavlin Radoslavov | b7bb9f0 | 2016-10-18 17:19:55 -0700 | [diff] [blame] | 665 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 666 | TEST_F(StackA2dpTest, test_a2dp_adjust_codec) { |
Pavlin Radoslavov | b7bb9f0 | 2016-10-18 17:19:55 -0700 | [diff] [blame] | 667 | uint8_t codec_info_sbc_test[AVDT_CODEC_SIZE]; |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 668 | uint8_t codec_info_aac_test[AVDT_CODEC_SIZE]; |
Pavlin Radoslavov | b7bb9f0 | 2016-10-18 17:19:55 -0700 | [diff] [blame] | 669 | uint8_t codec_info_non_a2dp_test[AVDT_CODEC_SIZE]; |
| 670 | |
| 671 | // Test updating a valid SBC codec that doesn't need adjustment |
| 672 | memset(codec_info_sbc_test, 0xAB, sizeof(codec_info_sbc_test)); |
| 673 | memcpy(codec_info_sbc_test, codec_info_sbc, sizeof(codec_info_sbc)); |
| 674 | EXPECT_TRUE(A2DP_AdjustCodec(codec_info_sbc_test)); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 675 | EXPECT_TRUE( |
| 676 | memcmp(codec_info_sbc_test, codec_info_sbc, sizeof(codec_info_sbc)) == 0); |
Pavlin Radoslavov | b7bb9f0 | 2016-10-18 17:19:55 -0700 | [diff] [blame] | 677 | |
| 678 | // Test updating a valid SBC codec that needs adjustment |
| 679 | memset(codec_info_sbc_test, 0xAB, sizeof(codec_info_sbc_test)); |
| 680 | memcpy(codec_info_sbc_test, codec_info_sbc, sizeof(codec_info_sbc)); |
| 681 | codec_info_sbc_test[6] = 54; // A2DP_SBC_MAX_BITPOOL + 1 |
| 682 | EXPECT_TRUE(A2DP_AdjustCodec(codec_info_sbc_test)); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 683 | EXPECT_TRUE( |
| 684 | memcmp(codec_info_sbc_test, codec_info_sbc, sizeof(codec_info_sbc)) == 0); |
Pavlin Radoslavov | b7bb9f0 | 2016-10-18 17:19:55 -0700 | [diff] [blame] | 685 | |
| 686 | // Test updating an invalid SBC codec |
| 687 | memset(codec_info_sbc_test, 0xAB, sizeof(codec_info_sbc_test)); |
| 688 | memcpy(codec_info_sbc_test, codec_info_sbc, sizeof(codec_info_sbc)); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 689 | codec_info_sbc_test[6] = 255; // Invalid MAX_BITPOOL |
Pavlin Radoslavov | b7bb9f0 | 2016-10-18 17:19:55 -0700 | [diff] [blame] | 690 | EXPECT_FALSE(A2DP_AdjustCodec(codec_info_sbc_test)); |
| 691 | |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 692 | // Test updating a valid AAC codec that doesn't need adjustment |
| 693 | memset(codec_info_aac_test, 0xAB, sizeof(codec_info_aac_test)); |
| 694 | memcpy(codec_info_aac_test, codec_info_aac, sizeof(codec_info_aac)); |
| 695 | EXPECT_TRUE(A2DP_AdjustCodec(codec_info_aac_test)); |
| 696 | EXPECT_TRUE( |
| 697 | memcmp(codec_info_aac_test, codec_info_aac, sizeof(codec_info_aac)) == 0); |
| 698 | |
Pavlin Radoslavov | b7bb9f0 | 2016-10-18 17:19:55 -0700 | [diff] [blame] | 699 | // Test updating a non-A2DP codec that is not recognized |
| 700 | memset(codec_info_non_a2dp_test, 0xAB, sizeof(codec_info_non_a2dp_test)); |
| 701 | memcpy(codec_info_non_a2dp_test, codec_info_non_a2dp, |
| 702 | sizeof(codec_info_non_a2dp)); |
| 703 | EXPECT_FALSE(A2DP_AdjustCodec(codec_info_non_a2dp_test)); |
| 704 | } |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 705 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 706 | TEST_F(StackA2dpTest, test_a2dp_source_codec_index) { |
Pavlin Radoslavov | f8dd02a | 2018-03-26 23:30:46 -0700 | [diff] [blame] | 707 | // Explicit tests for known Source codecs |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 708 | EXPECT_EQ(A2DP_SourceCodecIndex(codec_info_sbc), |
| 709 | BTAV_A2DP_CODEC_INDEX_SOURCE_SBC); |
koh.changseok | 444ea2c | 2017-07-04 02:37:42 +0900 | [diff] [blame] | 710 | EXPECT_EQ(A2DP_SourceCodecIndex(codec_info_sbc_capability), |
| 711 | BTAV_A2DP_CODEC_INDEX_SOURCE_SBC); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 712 | EXPECT_EQ(A2DP_SourceCodecIndex(codec_info_sbc_sink_capability), |
| 713 | BTAV_A2DP_CODEC_INDEX_SOURCE_SBC); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 714 | EXPECT_EQ(A2DP_SourceCodecIndex(codec_info_aac), |
| 715 | BTAV_A2DP_CODEC_INDEX_SOURCE_AAC); |
| 716 | EXPECT_EQ(A2DP_SourceCodecIndex(codec_info_aac_capability), |
| 717 | BTAV_A2DP_CODEC_INDEX_SOURCE_AAC); |
| 718 | EXPECT_EQ(A2DP_SourceCodecIndex(codec_info_aac_sink_capability), |
| 719 | BTAV_A2DP_CODEC_INDEX_SOURCE_AAC); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 720 | EXPECT_EQ(A2DP_SourceCodecIndex(codec_info_non_a2dp), |
| 721 | BTAV_A2DP_CODEC_INDEX_MAX); |
| 722 | } |
| 723 | |
Pavlin Radoslavov | f8dd02a | 2018-03-26 23:30:46 -0700 | [diff] [blame] | 724 | TEST_F(StackA2dpTest, test_a2dp_sink_codec_index) { |
| 725 | // Explicit tests for known Sink codecs |
| 726 | EXPECT_EQ(A2DP_SinkCodecIndex(codec_info_sbc), |
| 727 | BTAV_A2DP_CODEC_INDEX_SINK_SBC); |
| 728 | EXPECT_EQ(A2DP_SinkCodecIndex(codec_info_sbc_capability), |
| 729 | BTAV_A2DP_CODEC_INDEX_SINK_SBC); |
| 730 | EXPECT_EQ(A2DP_SinkCodecIndex(codec_info_sbc_sink_capability), |
| 731 | BTAV_A2DP_CODEC_INDEX_SINK_SBC); |
| 732 | EXPECT_EQ(A2DP_SinkCodecIndex(codec_info_aac), |
| 733 | BTAV_A2DP_CODEC_INDEX_SINK_AAC); |
| 734 | EXPECT_EQ(A2DP_SinkCodecIndex(codec_info_aac_capability), |
| 735 | BTAV_A2DP_CODEC_INDEX_SINK_AAC); |
| 736 | EXPECT_EQ(A2DP_SinkCodecIndex(codec_info_aac_sink_capability), |
| 737 | BTAV_A2DP_CODEC_INDEX_SINK_AAC); |
| 738 | EXPECT_EQ(A2DP_SinkCodecIndex(codec_info_non_a2dp), |
| 739 | BTAV_A2DP_CODEC_INDEX_MAX); |
| 740 | } |
| 741 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 742 | TEST_F(StackA2dpTest, test_a2dp_codec_index_str) { |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 743 | // Explicit tests for known codecs |
| 744 | EXPECT_STREQ(A2DP_CodecIndexStr(BTAV_A2DP_CODEC_INDEX_SOURCE_SBC), "SBC"); |
| 745 | EXPECT_STREQ(A2DP_CodecIndexStr(BTAV_A2DP_CODEC_INDEX_SINK_SBC), "SBC SINK"); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 746 | EXPECT_STREQ(A2DP_CodecIndexStr(BTAV_A2DP_CODEC_INDEX_SOURCE_AAC), "AAC"); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 747 | |
| 748 | // Test that the unknown codec string has not changed |
| 749 | EXPECT_STREQ(A2DP_CodecIndexStr(BTAV_A2DP_CODEC_INDEX_MAX), |
| 750 | "UNKNOWN CODEC INDEX"); |
| 751 | |
| 752 | // Test that each codec has a known string |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 753 | for (int i = BTAV_A2DP_CODEC_INDEX_MIN; i < BTAV_A2DP_CODEC_INDEX_MAX; i++) { |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 754 | btav_a2dp_codec_index_t codec_index = |
| 755 | static_cast<btav_a2dp_codec_index_t>(i); |
| 756 | EXPECT_STRNE(A2DP_CodecIndexStr(codec_index), "UNKNOWN CODEC INDEX"); |
| 757 | } |
| 758 | } |
| 759 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 760 | TEST_F(StackA2dpTest, test_a2dp_init_codec_config) { |
Pavlin Radoslavov | d752229 | 2017-11-24 19:12:11 -0800 | [diff] [blame] | 761 | AvdtpSepConfig avdt_cfg; |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 762 | |
| 763 | // |
| 764 | // Test for SBC Source |
| 765 | // |
| 766 | memset(&avdt_cfg, 0, sizeof(avdt_cfg)); |
| 767 | EXPECT_TRUE( |
| 768 | A2DP_InitCodecConfig(BTAV_A2DP_CODEC_INDEX_SOURCE_SBC, &avdt_cfg)); |
| 769 | // Compare the result codec with the local test codec info |
koh.changseok | 444ea2c | 2017-07-04 02:37:42 +0900 | [diff] [blame] | 770 | for (size_t i = 0; i < codec_info_sbc_capability[0] + 1; i++) { |
| 771 | EXPECT_EQ(avdt_cfg.codec_info[i], codec_info_sbc_capability[i]); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 772 | } |
| 773 | // Test for content protection |
| 774 | #if (BTA_AV_CO_CP_SCMS_T == TRUE) |
| 775 | EXPECT_EQ(avdt_cfg.protect_info[0], AVDT_CP_LOSC); |
| 776 | EXPECT_EQ(avdt_cfg.protect_info[1], (AVDT_CP_SCMS_T_ID & 0xFF)); |
| 777 | EXPECT_EQ(avdt_cfg.protect_info[2], ((AVDT_CP_SCMS_T_ID >> 8) & 0xFF)); |
| 778 | EXPECT_EQ(avdt_cfg.num_protect, 1); |
| 779 | #endif |
| 780 | |
| 781 | // |
| 782 | // Test for SBC Sink |
| 783 | // |
| 784 | memset(&avdt_cfg, 0, sizeof(avdt_cfg)); |
| 785 | EXPECT_TRUE(A2DP_InitCodecConfig(BTAV_A2DP_CODEC_INDEX_SINK_SBC, &avdt_cfg)); |
| 786 | // Compare the result codec with the local test codec info |
| 787 | for (size_t i = 0; i < codec_info_sbc_sink_capability[0] + 1; i++) { |
| 788 | EXPECT_EQ(avdt_cfg.codec_info[i], codec_info_sbc_sink_capability[i]); |
| 789 | } |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 790 | |
| 791 | // |
| 792 | // Test for AAC Source |
| 793 | // |
| 794 | memset(&avdt_cfg, 0, sizeof(avdt_cfg)); |
| 795 | EXPECT_TRUE( |
| 796 | A2DP_InitCodecConfig(BTAV_A2DP_CODEC_INDEX_SOURCE_AAC, &avdt_cfg)); |
| 797 | // Compare the result codec with the local test codec info |
| 798 | for (size_t i = 0; i < codec_info_aac_capability[0] + 1; i++) { |
| 799 | EXPECT_EQ(avdt_cfg.codec_info[i], codec_info_aac_capability[i]); |
| 800 | } |
| 801 | // Test for content protection |
| 802 | #if (BTA_AV_CO_CP_SCMS_T == TRUE) |
| 803 | EXPECT_EQ(avdt_cfg.protect_info[0], AVDT_CP_LOSC); |
| 804 | EXPECT_EQ(avdt_cfg.protect_info[1], (AVDT_CP_SCMS_T_ID & 0xFF)); |
| 805 | EXPECT_EQ(avdt_cfg.protect_info[2], ((AVDT_CP_SCMS_T_ID >> 8) & 0xFF)); |
| 806 | EXPECT_EQ(avdt_cfg.num_protect, 1); |
| 807 | #endif |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 808 | } |
| 809 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 810 | TEST_F(A2dpCodecConfigTest, createCodec) { |
| 811 | for (int i = BTAV_A2DP_CODEC_INDEX_MIN; i < BTAV_A2DP_CODEC_INDEX_MAX; i++) { |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 812 | btav_a2dp_codec_index_t codec_index = |
| 813 | static_cast<btav_a2dp_codec_index_t>(i); |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 814 | |
| 815 | // Ignore codecs that are not supported on the device |
| 816 | if (!has_codec_support(codec_index)) { |
| 817 | continue; |
| 818 | } |
| 819 | |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 820 | A2dpCodecConfig* codec_config = A2dpCodecConfig::createCodec(codec_index); |
| 821 | EXPECT_NE(codec_config, nullptr); |
| 822 | EXPECT_EQ(codec_config->codecIndex(), codec_index); |
| 823 | EXPECT_FALSE(codec_config->name().empty()); |
Pavlin Radoslavov | a6ba5ac | 2017-01-31 20:51:06 -0800 | [diff] [blame] | 824 | EXPECT_NE(codec_config->codecPriority(), BTAV_A2DP_CODEC_PRIORITY_DISABLED); |
| 825 | EXPECT_NE(codec_config->codecPriority(), BTAV_A2DP_CODEC_PRIORITY_DEFAULT); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 826 | delete codec_config; |
| 827 | } |
| 828 | } |
| 829 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 830 | TEST_F(A2dpCodecConfigTest, setCodecConfig) { |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 831 | uint8_t codec_info_result[AVDT_CODEC_SIZE]; |
| 832 | btav_a2dp_codec_index_t peer_codec_index; |
Pavlin Radoslavov | a6ba5ac | 2017-01-31 20:51:06 -0800 | [diff] [blame] | 833 | A2dpCodecs* a2dp_codecs = |
| 834 | new A2dpCodecs(std::vector<btav_a2dp_codec_config_t>()); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 835 | A2dpCodecConfig* codec_config; |
| 836 | |
| 837 | EXPECT_TRUE(a2dp_codecs->init()); |
| 838 | |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 839 | // Create the codec capability - SBC |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 840 | memset(codec_info_result, 0, sizeof(codec_info_result)); |
| 841 | peer_codec_index = A2DP_SourceCodecIndex(codec_info_sbc_sink_capability); |
| 842 | EXPECT_NE(peer_codec_index, BTAV_A2DP_CODEC_INDEX_MAX); |
| 843 | codec_config = |
| 844 | a2dp_codecs->findSourceCodecConfig(codec_info_sbc_sink_capability); |
| 845 | EXPECT_NE(codec_config, nullptr); |
Pavlin Radoslavov | 494e53e | 2017-01-25 17:00:23 -0800 | [diff] [blame] | 846 | EXPECT_TRUE(a2dp_codecs->setCodecConfig( |
| 847 | codec_info_sbc_sink_capability, true /* is_capability */, |
| 848 | codec_info_result, true /* select_current_codec */)); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 849 | EXPECT_EQ(a2dp_codecs->getCurrentCodecConfig(), codec_config); |
| 850 | // Compare the result codec with the local test codec info |
| 851 | for (size_t i = 0; i < codec_info_sbc[0] + 1; i++) { |
| 852 | EXPECT_EQ(codec_info_result[i], codec_info_sbc[i]); |
| 853 | } |
Pavlin Radoslavov | c95e5dd | 2017-05-10 17:09:00 -0700 | [diff] [blame] | 854 | EXPECT_EQ(codec_config->getAudioBitsPerSample(), 16); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 855 | |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 856 | // Create the codec capability - AAC |
| 857 | memset(codec_info_result, 0, sizeof(codec_info_result)); |
| 858 | peer_codec_index = A2DP_SourceCodecIndex(codec_info_aac_sink_capability); |
| 859 | EXPECT_NE(peer_codec_index, BTAV_A2DP_CODEC_INDEX_MAX); |
| 860 | codec_config = |
| 861 | a2dp_codecs->findSourceCodecConfig(codec_info_aac_sink_capability); |
| 862 | EXPECT_NE(codec_config, nullptr); |
Pavlin Radoslavov | 494e53e | 2017-01-25 17:00:23 -0800 | [diff] [blame] | 863 | EXPECT_TRUE(a2dp_codecs->setCodecConfig( |
| 864 | codec_info_aac_sink_capability, true /* is_capability */, |
| 865 | codec_info_result, true /* select_current_codec */)); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 866 | EXPECT_EQ(a2dp_codecs->getCurrentCodecConfig(), codec_config); |
| 867 | // Compare the result codec with the local test codec info |
| 868 | for (size_t i = 0; i < codec_info_aac[0] + 1; i++) { |
| 869 | EXPECT_EQ(codec_info_result[i], codec_info_aac[i]); |
| 870 | } |
Pavlin Radoslavov | c95e5dd | 2017-05-10 17:09:00 -0700 | [diff] [blame] | 871 | EXPECT_EQ(codec_config->getAudioBitsPerSample(), 16); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 872 | |
| 873 | // Create the codec config - SBC |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 874 | memset(codec_info_result, 0, sizeof(codec_info_result)); |
| 875 | peer_codec_index = A2DP_SourceCodecIndex(codec_info_sbc); |
| 876 | EXPECT_NE(peer_codec_index, BTAV_A2DP_CODEC_INDEX_MAX); |
| 877 | codec_config = a2dp_codecs->findSourceCodecConfig(codec_info_sbc); |
| 878 | EXPECT_NE(codec_config, nullptr); |
Pavlin Radoslavov | 494e53e | 2017-01-25 17:00:23 -0800 | [diff] [blame] | 879 | EXPECT_TRUE(a2dp_codecs->setCodecConfig( |
| 880 | codec_info_sbc, false /* is_capability */, codec_info_result, |
| 881 | true /* select_current_codec */)); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 882 | EXPECT_EQ(a2dp_codecs->getCurrentCodecConfig(), codec_config); |
| 883 | // Compare the result codec with the local test codec info |
| 884 | for (size_t i = 0; i < codec_info_sbc[0] + 1; i++) { |
| 885 | EXPECT_EQ(codec_info_result[i], codec_info_sbc[i]); |
| 886 | } |
Pavlin Radoslavov | 3b8391c | 2017-05-12 01:16:10 -0700 | [diff] [blame] | 887 | EXPECT_FALSE(codec_config->useRtpHeaderMarkerBit()); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 888 | |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 889 | // Create the codec config - AAC |
| 890 | memset(codec_info_result, 0, sizeof(codec_info_result)); |
| 891 | peer_codec_index = A2DP_SourceCodecIndex(codec_info_aac); |
| 892 | EXPECT_NE(peer_codec_index, BTAV_A2DP_CODEC_INDEX_MAX); |
| 893 | codec_config = a2dp_codecs->findSourceCodecConfig(codec_info_aac); |
| 894 | EXPECT_NE(codec_config, nullptr); |
Pavlin Radoslavov | 494e53e | 2017-01-25 17:00:23 -0800 | [diff] [blame] | 895 | EXPECT_TRUE(a2dp_codecs->setCodecConfig( |
| 896 | codec_info_aac, false /* is_capability */, codec_info_result, |
| 897 | true /* select_current_codec */)); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 898 | EXPECT_EQ(a2dp_codecs->getCurrentCodecConfig(), codec_config); |
| 899 | // Compare the result codec with the local test codec info |
| 900 | for (size_t i = 0; i < codec_info_aac[0] + 1; i++) { |
| 901 | EXPECT_EQ(codec_info_result[i], codec_info_aac[i]); |
| 902 | } |
Pavlin Radoslavov | 3b8391c | 2017-05-12 01:16:10 -0700 | [diff] [blame] | 903 | EXPECT_TRUE(codec_config->useRtpHeaderMarkerBit()); |
Pavlin Radoslavov | d5f4960 | 2017-01-03 16:53:18 -0800 | [diff] [blame] | 904 | |
Pavlin Radoslavov | f8dd02a | 2018-03-26 23:30:46 -0700 | [diff] [blame] | 905 | // Create the codec capability - SBC Sink |
| 906 | memset(codec_info_result, 0, sizeof(codec_info_result)); |
| 907 | peer_codec_index = A2DP_SinkCodecIndex(codec_info_sbc_capability); |
| 908 | EXPECT_NE(peer_codec_index, BTAV_A2DP_CODEC_INDEX_MAX); |
| 909 | codec_config = a2dp_codecs->findSinkCodecConfig(codec_info_sbc_capability); |
| 910 | EXPECT_NE(codec_config, nullptr); |
| 911 | EXPECT_TRUE(a2dp_codecs->setSinkCodecConfig( |
| 912 | codec_info_sbc_capability, true /* is_capability */, codec_info_result, |
| 913 | true /* select_current_codec */)); |
| 914 | EXPECT_EQ(a2dp_codecs->getCurrentCodecConfig(), codec_config); |
| 915 | // Compare the result codec with the local test codec info |
| 916 | for (size_t i = 0; i < codec_info_sbc[0] + 1; i++) { |
| 917 | EXPECT_EQ(codec_info_result[i], codec_info_sbc[i]); |
| 918 | } |
| 919 | EXPECT_EQ(codec_config->getAudioBitsPerSample(), 16); |
| 920 | |
| 921 | // Create the codec capability - AAC Sink |
| 922 | memset(codec_info_result, 0, sizeof(codec_info_result)); |
| 923 | peer_codec_index = A2DP_SinkCodecIndex(codec_info_aac_capability); |
| 924 | EXPECT_NE(peer_codec_index, BTAV_A2DP_CODEC_INDEX_MAX); |
| 925 | codec_config = a2dp_codecs->findSinkCodecConfig(codec_info_aac_capability); |
| 926 | EXPECT_NE(codec_config, nullptr); |
| 927 | EXPECT_TRUE(a2dp_codecs->setSinkCodecConfig( |
| 928 | codec_info_aac_capability, true /* is_capability */, codec_info_result, |
| 929 | true /* select_current_codec */)); |
| 930 | EXPECT_EQ(a2dp_codecs->getCurrentCodecConfig(), codec_config); |
| 931 | // Compare the result codec with the local test codec info |
| 932 | for (size_t i = 0; i < codec_info_aac[0] + 1; i++) { |
| 933 | EXPECT_EQ(codec_info_result[i], codec_info_aac[i]); |
| 934 | } |
| 935 | EXPECT_EQ(codec_config->getAudioBitsPerSample(), 16); |
| 936 | |
| 937 | // Create the codec config - SBC Sink |
| 938 | memset(codec_info_result, 0, sizeof(codec_info_result)); |
| 939 | peer_codec_index = A2DP_SinkCodecIndex(codec_info_sbc); |
| 940 | EXPECT_NE(peer_codec_index, BTAV_A2DP_CODEC_INDEX_MAX); |
| 941 | codec_config = a2dp_codecs->findSinkCodecConfig(codec_info_sbc); |
| 942 | EXPECT_NE(codec_config, nullptr); |
| 943 | EXPECT_TRUE(a2dp_codecs->setSinkCodecConfig( |
| 944 | codec_info_sbc, false /* is_capability */, codec_info_result, |
| 945 | true /* select_current_codec */)); |
| 946 | EXPECT_EQ(a2dp_codecs->getCurrentCodecConfig(), codec_config); |
| 947 | // Compare the result codec with the local test codec info |
| 948 | for (size_t i = 0; i < codec_info_sbc[0] + 1; i++) { |
| 949 | EXPECT_EQ(codec_info_result[i], codec_info_sbc[i]); |
| 950 | } |
| 951 | EXPECT_EQ(codec_config->getAudioBitsPerSample(), 16); |
| 952 | |
| 953 | // Create the codec config - AAC Sink |
| 954 | memset(codec_info_result, 0, sizeof(codec_info_result)); |
| 955 | peer_codec_index = A2DP_SinkCodecIndex(codec_info_aac); |
| 956 | EXPECT_NE(peer_codec_index, BTAV_A2DP_CODEC_INDEX_MAX); |
| 957 | codec_config = a2dp_codecs->findSinkCodecConfig(codec_info_aac); |
| 958 | EXPECT_NE(codec_config, nullptr); |
| 959 | EXPECT_TRUE(a2dp_codecs->setSinkCodecConfig( |
| 960 | codec_info_aac, false /* is_capability */, codec_info_result, |
| 961 | true /* select_current_codec */)); |
| 962 | EXPECT_EQ(a2dp_codecs->getCurrentCodecConfig(), codec_config); |
| 963 | // Compare the result codec with the local test codec info |
| 964 | for (size_t i = 0; i < codec_info_aac[0] + 1; i++) { |
| 965 | EXPECT_EQ(codec_info_result[i], codec_info_aac[i]); |
| 966 | } |
| 967 | EXPECT_EQ(codec_config->getAudioBitsPerSample(), 16); |
| 968 | |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 969 | // Test invalid codec info |
| 970 | uint8_t codec_info_sbc_test1[AVDT_CODEC_SIZE]; |
| 971 | memset(codec_info_result, 0, sizeof(codec_info_result)); |
| 972 | memset(codec_info_sbc_test1, 0, sizeof(codec_info_sbc_test1)); |
Pavlin Radoslavov | 494e53e | 2017-01-25 17:00:23 -0800 | [diff] [blame] | 973 | EXPECT_FALSE(a2dp_codecs->setCodecConfig( |
| 974 | codec_info_sbc_test1, true /* is_capability */, codec_info_result, |
| 975 | true /* select_current_codec */)); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 976 | delete a2dp_codecs; |
| 977 | } |
| 978 | |
Pavlin Radoslavov | 4decac3 | 2017-01-13 17:42:01 -0800 | [diff] [blame] | 979 | TEST_F(A2dpCodecConfigTest, init) { |
Pavlin Radoslavov | a6ba5ac | 2017-01-31 20:51:06 -0800 | [diff] [blame] | 980 | std::vector<btav_a2dp_codec_config_t> default_priorities; |
| 981 | A2dpCodecs codecs(default_priorities); |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 982 | |
| 983 | EXPECT_TRUE(codecs.init()); |
| 984 | |
| 985 | const std::list<A2dpCodecConfig*> orderedSourceCodecs = |
| 986 | codecs.orderedSourceCodecs(); |
| 987 | EXPECT_FALSE(orderedSourceCodecs.empty()); |
| 988 | |
| 989 | const std::list<A2dpCodecConfig*> orderedSinkCodecs = |
| 990 | codecs.orderedSinkCodecs(); |
| 991 | EXPECT_FALSE(orderedSinkCodecs.empty()); |
| 992 | } |