1 /*
2 * Copyright (C) 2021 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 #include <iostream>
18 #include <string>
19
20 #include <gtest/gtest.h>
21
22 #include <media/AidlConversion.h>
23 #include <media/AudioCommonTypes.h>
24
25 using namespace android;
26 using namespace android::aidl_utils;
27
28 using media::AudioDirectMode;
29 using media::AudioPortConfigFw;
30 using media::AudioPortDeviceExtSys;
31 using media::AudioPortFw;
32 using media::AudioPortRole;
33 using media::AudioPortType;
34 using media::audio::common::AudioChannelLayout;
35 using media::audio::common::AudioDevice;
36 using media::audio::common::AudioDeviceAddress;
37 using media::audio::common::AudioDeviceDescription;
38 using media::audio::common::AudioDeviceType;
39 using media::audio::common::AudioEncapsulationMetadataType;
40 using media::audio::common::AudioEncapsulationType;
41 using media::audio::common::AudioFormatDescription;
42 using media::audio::common::AudioFormatType;
43 using media::audio::common::AudioGain;
44 using media::audio::common::AudioGainConfig;
45 using media::audio::common::AudioGainMode;
46 using media::audio::common::AudioInputFlags;
47 using media::audio::common::AudioIoFlags;
48 using media::audio::common::AudioOutputFlags;
49 using media::audio::common::AudioPortDeviceExt;
50 using media::audio::common::AudioProfile;
51 using media::audio::common::AudioStandard;
52 using media::audio::common::ExtraAudioDescriptor;
53 using media::audio::common::Int;
54 using media::audio::common::MicrophoneDynamicInfo;
55 using media::audio::common::MicrophoneInfo;
56 using media::audio::common::PcmType;
57
58 // Provide value printers for types generated from AIDL
59 // They need to be in the same namespace as the types we intend to print
60 namespace android::media {
61 #define DEFINE_PRINTING_TEMPLATES() \
62 template <typename P> \
63 std::enable_if_t<std::is_base_of_v<::android::Parcelable, P>, std::ostream&> operator<<( \
64 std::ostream& os, const P& p) { \
65 return os << p.toString(); \
66 } \
67 template <typename E> \
68 std::enable_if_t<std::is_enum_v<E>, std::ostream&> operator<<(std::ostream& os, const E& e) { \
69 return os << toString(e); \
70 }
71 DEFINE_PRINTING_TEMPLATES();
72
73 namespace audio::common {
74 DEFINE_PRINTING_TEMPLATES();
75 } // namespace audio::common
76 #undef DEFINE_PRINTING_TEMPLATES
77 } // namespace android::media
78
79 namespace {
80
81 template <typename T>
hash(const T & t)82 size_t hash(const T& t) {
83 return std::hash<T>{}(t);
84 }
85
make_ACL_None()86 AudioChannelLayout make_ACL_None() {
87 return AudioChannelLayout{};
88 }
89
make_ACL_Invalid()90 AudioChannelLayout make_ACL_Invalid() {
91 return AudioChannelLayout::make<AudioChannelLayout::Tag::invalid>(0);
92 }
93
make_ACL_Stereo()94 AudioChannelLayout make_ACL_Stereo() {
95 return AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
96 AudioChannelLayout::LAYOUT_STEREO);
97 }
98
make_ACL_Tri()99 AudioChannelLayout make_ACL_Tri() {
100 return AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
101 AudioChannelLayout::LAYOUT_TRI);
102 }
103
make_ACL_LayoutArbitrary()104 AudioChannelLayout make_ACL_LayoutArbitrary() {
105 return AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
106 // Use channels that exist both for input and output,
107 // but doesn't form a known layout mask.
108 AudioChannelLayout::CHANNEL_FRONT_LEFT | AudioChannelLayout::CHANNEL_FRONT_RIGHT |
109 AudioChannelLayout::CHANNEL_TOP_SIDE_LEFT | AudioChannelLayout::CHANNEL_TOP_SIDE_RIGHT);
110 }
111
make_ACL_ChannelIndex2()112 AudioChannelLayout make_ACL_ChannelIndex2() {
113 return AudioChannelLayout::make<AudioChannelLayout::Tag::indexMask>(
114 AudioChannelLayout::INDEX_MASK_2);
115 }
116
make_ACL_ChannelIndexArbitrary()117 AudioChannelLayout make_ACL_ChannelIndexArbitrary() {
118 // Use channels 1 and 3.
119 return AudioChannelLayout::make<AudioChannelLayout::Tag::indexMask>(5);
120 }
121
make_ACL_VoiceCall()122 AudioChannelLayout make_ACL_VoiceCall() {
123 return AudioChannelLayout::make<AudioChannelLayout::Tag::voiceMask>(
124 AudioChannelLayout::VOICE_CALL_MONO);
125 }
126
make_AudioDeviceDescription(AudioDeviceType type,const std::string & connection="")127 AudioDeviceDescription make_AudioDeviceDescription(AudioDeviceType type,
128 const std::string& connection = "") {
129 AudioDeviceDescription result;
130 result.type = type;
131 result.connection = connection;
132 return result;
133 }
134
make_ADD_None()135 AudioDeviceDescription make_ADD_None() {
136 return AudioDeviceDescription{};
137 }
138
make_ADD_DefaultIn()139 AudioDeviceDescription make_ADD_DefaultIn() {
140 return make_AudioDeviceDescription(AudioDeviceType::IN_DEFAULT);
141 }
142
make_ADD_MicIn()143 AudioDeviceDescription make_ADD_MicIn() {
144 return make_AudioDeviceDescription(AudioDeviceType::IN_MICROPHONE);
145 }
146
make_ADD_RSubmixIn()147 AudioDeviceDescription make_ADD_RSubmixIn() {
148 return make_AudioDeviceDescription(AudioDeviceType::IN_SUBMIX,
149 AudioDeviceDescription::CONNECTION_VIRTUAL());
150 }
151
make_ADD_DefaultOut()152 AudioDeviceDescription make_ADD_DefaultOut() {
153 return make_AudioDeviceDescription(AudioDeviceType::OUT_DEFAULT);
154 }
155
make_ADD_WiredHeadset()156 AudioDeviceDescription make_ADD_WiredHeadset() {
157 return make_AudioDeviceDescription(AudioDeviceType::OUT_HEADSET,
158 AudioDeviceDescription::CONNECTION_ANALOG());
159 }
160
make_ADD_BtScoHeadset()161 AudioDeviceDescription make_ADD_BtScoHeadset() {
162 return make_AudioDeviceDescription(AudioDeviceType::OUT_HEADSET,
163 AudioDeviceDescription::CONNECTION_BT_SCO());
164 }
165
make_ADD_BtA2dpHeadphone()166 AudioDeviceDescription make_ADD_BtA2dpHeadphone() {
167 return make_AudioDeviceDescription(AudioDeviceType::OUT_HEADPHONE,
168 AudioDeviceDescription::CONNECTION_BT_A2DP());
169 }
170
make_ADD_BtLeHeadset()171 AudioDeviceDescription make_ADD_BtLeHeadset() {
172 return make_AudioDeviceDescription(AudioDeviceType::OUT_HEADSET,
173 AudioDeviceDescription::CONNECTION_BT_LE());
174 }
175
make_ADD_BtLeBroadcast()176 AudioDeviceDescription make_ADD_BtLeBroadcast() {
177 return make_AudioDeviceDescription(AudioDeviceType::OUT_BROADCAST,
178 AudioDeviceDescription::CONNECTION_BT_LE());
179 }
180
make_ADD_IpV4Device()181 AudioDeviceDescription make_ADD_IpV4Device() {
182 return make_AudioDeviceDescription(AudioDeviceType::OUT_DEVICE,
183 AudioDeviceDescription::CONNECTION_IP_V4());
184 }
185
make_ADD_UsbHeadset()186 AudioDeviceDescription make_ADD_UsbHeadset() {
187 return make_AudioDeviceDescription(AudioDeviceType::OUT_HEADSET,
188 AudioDeviceDescription::CONNECTION_USB());
189 }
190
make_AudioDevice(const AudioDeviceDescription & type,const AudioDeviceAddress & address)191 AudioDevice make_AudioDevice(const AudioDeviceDescription& type,
192 const AudioDeviceAddress& address) {
193 AudioDevice result;
194 result.type = type;
195 result.address = address;
196 return result;
197 }
198
make_AudioFormatDescription(AudioFormatType type)199 AudioFormatDescription make_AudioFormatDescription(AudioFormatType type) {
200 AudioFormatDescription result;
201 result.type = type;
202 return result;
203 }
204
make_AudioFormatDescription(PcmType pcm)205 AudioFormatDescription make_AudioFormatDescription(PcmType pcm) {
206 auto result = make_AudioFormatDescription(AudioFormatType::PCM);
207 result.pcm = pcm;
208 return result;
209 }
210
make_AudioFormatDescription(const std::string & encoding)211 AudioFormatDescription make_AudioFormatDescription(const std::string& encoding) {
212 AudioFormatDescription result;
213 result.encoding = encoding;
214 return result;
215 }
216
make_AudioFormatDescription(PcmType transport,const std::string & encoding)217 AudioFormatDescription make_AudioFormatDescription(PcmType transport, const std::string& encoding) {
218 auto result = make_AudioFormatDescription(encoding);
219 result.pcm = transport;
220 return result;
221 }
222
make_AFD_Default()223 AudioFormatDescription make_AFD_Default() {
224 return AudioFormatDescription{};
225 }
226
make_AFD_Invalid()227 AudioFormatDescription make_AFD_Invalid() {
228 return make_AudioFormatDescription(AudioFormatType::SYS_RESERVED_INVALID);
229 }
230
make_AFD_Pcm16Bit()231 AudioFormatDescription make_AFD_Pcm16Bit() {
232 return make_AudioFormatDescription(PcmType::INT_16_BIT);
233 }
234
make_AFD_Bitstream()235 AudioFormatDescription make_AFD_Bitstream() {
236 return make_AudioFormatDescription("example");
237 }
238
make_AFD_Encap()239 AudioFormatDescription make_AFD_Encap() {
240 return make_AudioFormatDescription(PcmType::INT_16_BIT, "example.encap");
241 }
242
make_AFD_Encap_with_Enc()243 AudioFormatDescription make_AFD_Encap_with_Enc() {
244 auto afd = make_AFD_Encap();
245 afd.encoding += "+example";
246 return afd;
247 }
248
make_TrackSecondaryOutputInfo()249 android::media::TrackSecondaryOutputInfo make_TrackSecondaryOutputInfo() {
250 android::media::TrackSecondaryOutputInfo result;
251 result.portId = 1;
252 result.secondaryOutputIds = {0, 5, 7};
253 return result;
254 }
255
make_ExtraAudioDescriptor(AudioStandard audioStandard,AudioEncapsulationType audioEncapsulationType)256 ExtraAudioDescriptor make_ExtraAudioDescriptor(AudioStandard audioStandard,
257 AudioEncapsulationType audioEncapsulationType) {
258 ExtraAudioDescriptor result;
259 result.standard = audioStandard;
260 result.audioDescriptor = {0xb4, 0xaf, 0x98, 0x1a};
261 result.encapsulationType = audioEncapsulationType;
262 return result;
263 }
264
265 } // namespace
266
267 // Verify that two independently constructed ADDs/AFDs have the same hash.
268 // This ensures that regardless of whether the ADD/AFD instance originates
269 // from, it can be correctly compared to other ADD/AFD instance. Thus,
270 // for example, a 16-bit integer format description provided by HAL
271 // is identical to the same format description constructed by the framework.
272 class HashIdentityTest : public ::testing::Test {
273 public:
274 template <typename T>
verifyHashIdentity(const std::vector<std::function<T ()>> & valueGens)275 void verifyHashIdentity(const std::vector<std::function<T()>>& valueGens) {
276 for (size_t i = 0; i < valueGens.size(); ++i) {
277 for (size_t j = 0; j < valueGens.size(); ++j) {
278 if (i == j) {
279 EXPECT_EQ(hash(valueGens[i]()), hash(valueGens[i]())) << i;
280 } else {
281 EXPECT_NE(hash(valueGens[i]()), hash(valueGens[j]())) << i << ", " << j;
282 }
283 }
284 }
285 }
286 };
287
TEST_F(HashIdentityTest,AudioChannelLayoutHashIdentity)288 TEST_F(HashIdentityTest, AudioChannelLayoutHashIdentity) {
289 verifyHashIdentity<AudioChannelLayout>({make_ACL_None, make_ACL_Invalid, make_ACL_Stereo,
290 make_ACL_LayoutArbitrary, make_ACL_ChannelIndex2,
291 make_ACL_ChannelIndexArbitrary, make_ACL_VoiceCall});
292 }
293
TEST_F(HashIdentityTest,AudioDeviceDescriptionHashIdentity)294 TEST_F(HashIdentityTest, AudioDeviceDescriptionHashIdentity) {
295 verifyHashIdentity<AudioDeviceDescription>({make_ADD_None, make_ADD_DefaultIn,
296 make_ADD_DefaultOut, make_ADD_WiredHeadset,
297 make_ADD_BtScoHeadset});
298 }
299
TEST_F(HashIdentityTest,AudioFormatDescriptionHashIdentity)300 TEST_F(HashIdentityTest, AudioFormatDescriptionHashIdentity) {
301 verifyHashIdentity<AudioFormatDescription>({make_AFD_Default, make_AFD_Invalid,
302 make_AFD_Pcm16Bit, make_AFD_Bitstream,
303 make_AFD_Encap, make_AFD_Encap_with_Enc});
304 }
305
306 using ChannelLayoutParam = std::tuple<AudioChannelLayout, bool /*isInput*/>;
307 class AudioChannelLayoutRoundTripTest : public testing::TestWithParam<ChannelLayoutParam> {};
TEST_P(AudioChannelLayoutRoundTripTest,Aidl2Legacy2Aidl)308 TEST_P(AudioChannelLayoutRoundTripTest, Aidl2Legacy2Aidl) {
309 const auto initial = std::get<0>(GetParam());
310 const bool isInput = std::get<1>(GetParam());
311 auto conv = aidl2legacy_AudioChannelLayout_audio_channel_mask_t(initial, isInput);
312 ASSERT_TRUE(conv.ok());
313 auto convBack = legacy2aidl_audio_channel_mask_t_AudioChannelLayout(conv.value(), isInput);
314 ASSERT_TRUE(convBack.ok());
315 EXPECT_EQ(initial, convBack.value());
316 }
317
318 INSTANTIATE_TEST_SUITE_P(
319 AudioChannelLayoutRoundTrip, AudioChannelLayoutRoundTripTest,
320 testing::Combine(
321 testing::Values(AudioChannelLayout{}, make_ACL_Invalid(), make_ACL_Stereo(),
322 make_ACL_Tri(), make_ACL_LayoutArbitrary(),
323 make_ACL_ChannelIndex2(), make_ACL_ChannelIndexArbitrary(),
324 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
325 AudioChannelLayout::CHANNEL_FRONT_LEFT),
326 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
327 AudioChannelLayout::CHANNEL_FRONT_RIGHT),
328 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
329 AudioChannelLayout::CHANNEL_BACK_CENTER),
330 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
331 AudioChannelLayout::CHANNEL_BACK_LEFT),
332 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
333 AudioChannelLayout::CHANNEL_BACK_RIGHT),
334 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
335 AudioChannelLayout::CHANNEL_FRONT_CENTER),
336 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
337 AudioChannelLayout::CHANNEL_LOW_FREQUENCY),
338 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
339 AudioChannelLayout::CHANNEL_TOP_SIDE_LEFT),
340 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
341 AudioChannelLayout::CHANNEL_TOP_SIDE_RIGHT)),
342 testing::Values(false, true)));
343 INSTANTIATE_TEST_SUITE_P(AudioChannelVoiceRoundTrip, AudioChannelLayoutRoundTripTest,
344 // In legacy constants the voice call is only defined for input.
345 testing::Combine(testing::Values(make_ACL_VoiceCall()),
346 testing::Values(true)));
347
348 INSTANTIATE_TEST_SUITE_P(
349 OutAudioChannelLayoutLayoutRoundTrip, AudioChannelLayoutRoundTripTest,
350 testing::Combine(
351 testing::Values(AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
352 AudioChannelLayout::CHANNEL_FRONT_LEFT_OF_CENTER),
353 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
354 AudioChannelLayout::CHANNEL_FRONT_RIGHT_OF_CENTER),
355 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
356 AudioChannelLayout::CHANNEL_SIDE_LEFT),
357 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
358 AudioChannelLayout::CHANNEL_SIDE_RIGHT),
359 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
360 AudioChannelLayout::CHANNEL_TOP_CENTER),
361 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
362 AudioChannelLayout::CHANNEL_TOP_FRONT_LEFT),
363 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
364 AudioChannelLayout::CHANNEL_TOP_FRONT_CENTER),
365 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
366 AudioChannelLayout::CHANNEL_TOP_FRONT_RIGHT),
367 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
368 AudioChannelLayout::CHANNEL_TOP_BACK_LEFT),
369 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
370 AudioChannelLayout::CHANNEL_TOP_BACK_CENTER),
371 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
372 AudioChannelLayout::CHANNEL_TOP_BACK_RIGHT),
373 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
374 AudioChannelLayout::CHANNEL_BOTTOM_FRONT_LEFT),
375 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
376 AudioChannelLayout::CHANNEL_BOTTOM_FRONT_CENTER),
377 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
378 AudioChannelLayout::CHANNEL_BOTTOM_FRONT_RIGHT),
379 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
380 AudioChannelLayout::CHANNEL_LOW_FREQUENCY_2),
381 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
382 AudioChannelLayout::CHANNEL_FRONT_WIDE_LEFT),
383 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
384 AudioChannelLayout::CHANNEL_FRONT_WIDE_RIGHT),
385 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
386 AudioChannelLayout::CHANNEL_HAPTIC_A),
387 AudioChannelLayout::make<AudioChannelLayout::Tag::layoutMask>(
388 AudioChannelLayout::CHANNEL_HAPTIC_B)),
389 testing::Values(false)));
390
391 using ChannelLayoutEdgeCaseParam = std::tuple<int /*legacy*/, bool /*isInput*/, bool /*isValid*/>;
392 class AudioChannelLayoutEdgeCaseTest : public testing::TestWithParam<ChannelLayoutEdgeCaseParam> {};
TEST_P(AudioChannelLayoutEdgeCaseTest,Legacy2Aidl)393 TEST_P(AudioChannelLayoutEdgeCaseTest, Legacy2Aidl) {
394 const audio_channel_mask_t legacy = static_cast<audio_channel_mask_t>(std::get<0>(GetParam()));
395 const bool isInput = std::get<1>(GetParam());
396 const bool isValid = std::get<2>(GetParam());
397 auto conv = legacy2aidl_audio_channel_mask_t_AudioChannelLayout(legacy, isInput);
398 EXPECT_EQ(isValid, conv.ok());
399 }
400 INSTANTIATE_TEST_SUITE_P(
401 AudioChannelLayoutEdgeCase, AudioChannelLayoutEdgeCaseTest,
402 testing::Values(
403 // Valid legacy input masks.
404 std::make_tuple(AUDIO_CHANNEL_IN_VOICE_UPLINK_MONO, true, true),
405 std::make_tuple(AUDIO_CHANNEL_IN_VOICE_DNLINK_MONO, true, true),
406 std::make_tuple(AUDIO_CHANNEL_IN_VOICE_CALL_MONO, true, true),
407 // Valid legacy output masks.
408 std::make_tuple(
409 // This has the same numerical representation as Mask 'A' below
410 AUDIO_CHANNEL_OUT_FRONT_CENTER | AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
411 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT,
412 false, true),
413 std::make_tuple(
414 // This has the same numerical representation as Mask 'B' below
415 AUDIO_CHANNEL_OUT_FRONT_CENTER | AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
416 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT,
417 false, true),
418 // Invalid legacy input masks.
419 std::make_tuple(AUDIO_CHANNEL_IN_6, true, false),
420 std::make_tuple(AUDIO_CHANNEL_IN_6 | AUDIO_CHANNEL_IN_FRONT_PROCESSED, true, false),
421 std::make_tuple(AUDIO_CHANNEL_IN_PRESSURE | AUDIO_CHANNEL_IN_X_AXIS |
422 AUDIO_CHANNEL_IN_Y_AXIS | AUDIO_CHANNEL_IN_Z_AXIS,
423 true, false),
424 std::make_tuple( // Mask 'A'
425 AUDIO_CHANNEL_IN_STEREO | AUDIO_CHANNEL_IN_VOICE_UPLINK, true, false),
426 std::make_tuple( // Mask 'B'
427 AUDIO_CHANNEL_IN_STEREO | AUDIO_CHANNEL_IN_VOICE_DNLINK, true, false)));
428
429 class AudioDeviceDescriptionRoundTripTest : public testing::TestWithParam<AudioDeviceDescription> {
430 };
TEST_P(AudioDeviceDescriptionRoundTripTest,Aidl2Legacy2Aidl)431 TEST_P(AudioDeviceDescriptionRoundTripTest, Aidl2Legacy2Aidl) {
432 const auto initial = GetParam();
433 auto conv = aidl2legacy_AudioDeviceDescription_audio_devices_t(initial);
434 ASSERT_TRUE(conv.ok());
435 auto convBack = legacy2aidl_audio_devices_t_AudioDeviceDescription(conv.value());
436 ASSERT_TRUE(convBack.ok());
437 EXPECT_EQ(initial, convBack.value());
438 }
439 INSTANTIATE_TEST_SUITE_P(AudioDeviceDescriptionRoundTrip, AudioDeviceDescriptionRoundTripTest,
440 testing::Values(AudioDeviceDescription{}, make_ADD_DefaultIn(),
441 make_ADD_DefaultOut(), make_ADD_WiredHeadset(),
442 make_ADD_BtScoHeadset()));
443
444 class AudioDeviceRoundTripTest : public testing::TestWithParam<AudioDevice> {};
TEST_P(AudioDeviceRoundTripTest,Aidl2Legacy2Aidl)445 TEST_P(AudioDeviceRoundTripTest, Aidl2Legacy2Aidl) {
446 const auto initial = GetParam();
447 audio_devices_t legacyType;
448 String8 legacyAddress;
449 status_t status = aidl2legacy_AudioDevice_audio_device(initial, &legacyType, &legacyAddress);
450 ASSERT_EQ(OK, status);
451 auto convBack = legacy2aidl_audio_device_AudioDevice(legacyType, legacyAddress);
452 ASSERT_TRUE(convBack.ok());
453 EXPECT_EQ(initial, convBack.value());
454 }
455 INSTANTIATE_TEST_SUITE_P(
456 AudioDeviceRoundTrip, AudioDeviceRoundTripTest,
457 testing::Values(
458 make_AudioDevice(make_ADD_MicIn(),
459 AudioDeviceAddress::make<AudioDeviceAddress::Tag::id>("bottom")),
460 make_AudioDevice(make_ADD_RSubmixIn(),
461 AudioDeviceAddress::make<AudioDeviceAddress::Tag::id>("1:2-in-3")),
462 // The case of a "blueprint" device port for an external device.
463 make_AudioDevice(make_ADD_BtScoHeadset(),
464 AudioDeviceAddress::make<AudioDeviceAddress::Tag::id>("")),
465 make_AudioDevice(make_ADD_BtScoHeadset(),
466 AudioDeviceAddress::make<AudioDeviceAddress::Tag::mac>(
467 std::vector<uint8_t>{1, 2, 3, 4, 5, 6})),
468 // Another "blueprint"
469 make_AudioDevice(make_ADD_BtA2dpHeadphone(),
470 AudioDeviceAddress::make<AudioDeviceAddress::Tag::id>("")),
471 make_AudioDevice(make_ADD_BtA2dpHeadphone(),
472 AudioDeviceAddress::make<AudioDeviceAddress::Tag::mac>(
473 std::vector<uint8_t>{1, 2, 3, 4, 5, 6})),
474 make_AudioDevice(make_ADD_BtLeHeadset(),
475 AudioDeviceAddress::make<AudioDeviceAddress::Tag::mac>(
476 std::vector<uint8_t>{1, 2, 3, 4, 5, 6})),
477 make_AudioDevice(make_ADD_BtLeBroadcast(),
478 AudioDeviceAddress::make<AudioDeviceAddress::Tag::id>("42")),
479 make_AudioDevice(make_ADD_IpV4Device(),
480 AudioDeviceAddress::make<AudioDeviceAddress::Tag::ipv4>(
481 std::vector<uint8_t>{192, 168, 0, 1})),
482 make_AudioDevice(make_ADD_UsbHeadset(),
483 AudioDeviceAddress::make<AudioDeviceAddress::Tag::alsa>(
484 std::vector<int32_t>{1, 2}))));
485
486 class AudioFormatDescriptionRoundTripTest : public testing::TestWithParam<AudioFormatDescription> {
487 };
TEST_P(AudioFormatDescriptionRoundTripTest,Aidl2Legacy2Aidl)488 TEST_P(AudioFormatDescriptionRoundTripTest, Aidl2Legacy2Aidl) {
489 const auto initial = GetParam();
490 auto conv = aidl2legacy_AudioFormatDescription_audio_format_t(initial);
491 ASSERT_TRUE(conv.ok());
492 auto convBack = legacy2aidl_audio_format_t_AudioFormatDescription(conv.value());
493 ASSERT_TRUE(convBack.ok());
494 EXPECT_EQ(initial, convBack.value());
495 }
496 INSTANTIATE_TEST_SUITE_P(AudioFormatDescriptionRoundTrip, AudioFormatDescriptionRoundTripTest,
497 testing::Values(make_AFD_Invalid(), AudioFormatDescription{},
498 make_AFD_Pcm16Bit()));
499
createAudioPortConfigFw(const AudioChannelLayout & layout,const AudioFormatDescription & format,const AudioDeviceDescription & device)500 AudioPortConfigFw createAudioPortConfigFw(const AudioChannelLayout& layout,
501 const AudioFormatDescription& format,
502 const AudioDeviceDescription& device) {
503 const bool isInput = device.type < AudioDeviceType::OUT_DEFAULT;
504 AudioPortConfigFw result;
505 result.hal.id = 43;
506 result.hal.portId = 42;
507 Int sr44100;
508 sr44100.value = 44100;
509 result.hal.sampleRate = sr44100;
510 result.hal.channelMask = layout;
511 result.hal.format = format;
512 AudioGainConfig gain;
513 gain.mode = 1 << static_cast<int>(AudioGainMode::JOINT);
514 gain.values = std::vector<int32_t>({100});
515 result.hal.gain = gain;
516 AudioPortDeviceExt ext;
517 AudioDevice audioDevice;
518 audioDevice.type = device;
519 ext.device = audioDevice;
520 result.hal.ext = ext;
521 result.sys.role = isInput ? AudioPortRole::SOURCE : AudioPortRole::SINK;
522 result.sys.type = AudioPortType::DEVICE;
523 AudioPortDeviceExtSys sysDevice;
524 sysDevice.hwModule = 1;
525 result.sys.ext = sysDevice;
526 return result;
527 }
528
529 using AudioPortConfigParam =
530 std::tuple<AudioChannelLayout, AudioFormatDescription, AudioDeviceDescription>;
531 class AudioPortConfigRoundTripTest : public testing::TestWithParam<AudioPortConfigParam> {};
TEST_P(AudioPortConfigRoundTripTest,Aidl2Legacy2Aidl)532 TEST_P(AudioPortConfigRoundTripTest, Aidl2Legacy2Aidl) {
533 const AudioChannelLayout layout = std::get<0>(GetParam());
534 const AudioFormatDescription format = std::get<1>(GetParam());
535 const AudioDeviceDescription device = std::get<2>(GetParam());
536 const bool isInput = device.type < AudioDeviceType::OUT_DEFAULT;
537 AudioPortConfigFw initial = createAudioPortConfigFw(layout, format, device);
538 {
539 audio_port_config conv{};
540 int32_t portId = -1;
541 status_t status =
542 aidl2legacy_AudioPortConfig_audio_port_config(initial.hal, isInput, &conv, &portId);
543 ASSERT_EQ(OK, status);
544 EXPECT_NE(-1, portId);
545 auto convBack = legacy2aidl_audio_port_config_AudioPortConfig(conv, isInput, portId);
546 ASSERT_TRUE(convBack.ok());
547 EXPECT_EQ(initial.hal, convBack.value());
548 }
549 {
550 int32_t portId = -1;
551 auto conv = aidl2legacy_AudioPortConfigFw_audio_port_config(initial, &portId);
552 ASSERT_TRUE(conv.ok());
553 EXPECT_NE(-1, portId);
554 auto convBack = legacy2aidl_audio_port_config_AudioPortConfigFw(conv.value(), portId);
555 ASSERT_TRUE(convBack.ok());
556 EXPECT_EQ(initial, convBack.value());
557 }
558 }
559 INSTANTIATE_TEST_SUITE_P(
560 AudioPortConfig, AudioPortConfigRoundTripTest,
561 testing::Combine(testing::Values(make_ACL_Stereo(), make_ACL_ChannelIndex2()),
562 testing::Values(make_AFD_Pcm16Bit()),
563 testing::Values(make_ADD_DefaultIn(), make_ADD_DefaultOut(),
564 make_ADD_WiredHeadset())));
565
566 class AudioPortFwRoundTripTest : public testing::TestWithParam<AudioDeviceDescription> {
567 public:
createProfile(const AudioFormatDescription & format,const std::vector<AudioChannelLayout> & channelMasks,const std::vector<int32_t> & sampleRates)568 AudioProfile createProfile(const AudioFormatDescription& format,
569 const std::vector<AudioChannelLayout>& channelMasks,
570 const std::vector<int32_t>& sampleRates) {
571 AudioProfile profile;
572 profile.format = format;
573 profile.channelMasks = channelMasks;
574 profile.sampleRates = sampleRates;
575 return profile;
576 }
577 };
TEST_P(AudioPortFwRoundTripTest,Aidl2Legacy2Aidl)578 TEST_P(AudioPortFwRoundTripTest, Aidl2Legacy2Aidl) {
579 const AudioDeviceDescription device = GetParam();
580 const bool isInput = device.type < AudioDeviceType::OUT_DEFAULT;
581 AudioPortFw initial;
582 initial.hal.id = 42;
583 initial.hal.profiles.push_back(createProfile(
584 make_AFD_Pcm16Bit(), {make_ACL_Stereo(), make_ACL_ChannelIndex2()}, {44100, 48000}));
585 if (isInput) {
586 initial.hal.flags = AudioIoFlags::make<AudioIoFlags::Tag::input>(0);
587 } else {
588 initial.hal.flags = AudioIoFlags::make<AudioIoFlags::Tag::output>(0);
589 }
590 AudioGain initialGain;
591 initialGain.mode = 1 << static_cast<int>(AudioGainMode::JOINT);
592 initialGain.channelMask = make_ACL_Stereo();
593 initial.hal.gains.push_back(initialGain);
594 AudioPortDeviceExt initialExt;
595 AudioDevice initialDevice;
596 initialDevice.type = device;
597 initialExt.device = initialDevice;
598 initial.hal.ext = initialExt;
599 {
600 auto conv = aidl2legacy_AudioPort_audio_port_v7(initial.hal, isInput);
601 ASSERT_TRUE(conv.ok());
602 auto convBack = legacy2aidl_audio_port_v7_AudioPort(conv.value(), isInput);
603 ASSERT_TRUE(convBack.ok());
604 EXPECT_EQ(initial.hal, convBack.value());
605 }
606 initial.sys.role = isInput ? AudioPortRole::SOURCE : AudioPortRole::SINK;
607 initial.sys.type = AudioPortType::DEVICE;
608 initial.sys.profiles.resize(initial.hal.profiles.size());
609 initial.sys.gains.resize(initial.hal.gains.size());
610 initial.sys.activeConfig =
611 createAudioPortConfigFw(make_ACL_Stereo(), make_AFD_Pcm16Bit(), device);
612 initial.sys.activeConfig.hal.flags = initial.hal.flags;
613 AudioPortDeviceExtSys initialSysDevice;
614 initialSysDevice.hwModule = 1;
615 initial.sys.ext = initialSysDevice;
616 {
617 auto conv = aidl2legacy_AudioPortFw_audio_port_v7(initial);
618 ASSERT_TRUE(conv.ok());
619 auto convBack = legacy2aidl_audio_port_v7_AudioPortFw(conv.value());
620 ASSERT_TRUE(convBack.ok());
621 EXPECT_EQ(initial, convBack.value());
622 }
623 }
624 INSTANTIATE_TEST_SUITE_P(AudioPortFw, AudioPortFwRoundTripTest,
625 testing::Values(make_ADD_DefaultIn(), make_ADD_DefaultOut(),
626 make_ADD_WiredHeadset()));
627
628 class AudioDirectModeRoundTripTest : public testing::TestWithParam<AudioDirectMode> {};
TEST_P(AudioDirectModeRoundTripTest,Aidl2Legacy2Aidl)629 TEST_P(AudioDirectModeRoundTripTest, Aidl2Legacy2Aidl) {
630 const auto initial = GetParam();
631 auto conv = aidl2legacy_AudioDirectMode_audio_direct_mode_t(initial);
632 ASSERT_TRUE(conv.ok());
633 auto convBack = legacy2aidl_audio_direct_mode_t_AudioDirectMode(conv.value());
634 ASSERT_TRUE(convBack.ok());
635 EXPECT_EQ(initial, convBack.value());
636 }
637 INSTANTIATE_TEST_SUITE_P(AudioDirectMode, AudioDirectModeRoundTripTest,
638 testing::Values(AudioDirectMode::NONE, AudioDirectMode::OFFLOAD,
639 AudioDirectMode::OFFLOAD_GAPLESS,
640 AudioDirectMode::BITSTREAM));
641
642 class AudioStandardRoundTripTest : public testing::TestWithParam<AudioStandard> {};
TEST_P(AudioStandardRoundTripTest,Aidl2Legacy2Aidl)643 TEST_P(AudioStandardRoundTripTest, Aidl2Legacy2Aidl) {
644 const auto initial = GetParam();
645 auto conv = aidl2legacy_AudioStandard_audio_standard_t(initial);
646 ASSERT_TRUE(conv.ok());
647 auto convBack = legacy2aidl_audio_standard_t_AudioStandard(conv.value());
648 ASSERT_TRUE(convBack.ok());
649 EXPECT_EQ(initial, convBack.value());
650 }
651 INSTANTIATE_TEST_SUITE_P(AudioStandard, AudioStandardRoundTripTest,
652 testing::Values(AudioStandard::NONE, AudioStandard::EDID,
653 AudioStandard::SADB, AudioStandard::VSADB));
654
655 class AudioEncapsulationMetadataTypeRoundTripTest
656 : public testing::TestWithParam<AudioEncapsulationMetadataType> {};
TEST_P(AudioEncapsulationMetadataTypeRoundTripTest,Aidl2Legacy2Aidl)657 TEST_P(AudioEncapsulationMetadataTypeRoundTripTest, Aidl2Legacy2Aidl) {
658 const auto initial = GetParam();
659 auto conv =
660 aidl2legacy_AudioEncapsulationMetadataType_audio_encapsulation_metadata_type_t(initial);
661 ASSERT_TRUE(conv.ok());
662 auto convBack = legacy2aidl_audio_encapsulation_metadata_type_t_AudioEncapsulationMetadataType(
663 conv.value());
664 ASSERT_TRUE(convBack.ok());
665 EXPECT_EQ(initial, convBack.value());
666 }
667 INSTANTIATE_TEST_SUITE_P(AudioEncapsulationMetadataType,
668 AudioEncapsulationMetadataTypeRoundTripTest,
669 testing::Values(AudioEncapsulationMetadataType::NONE,
670 AudioEncapsulationMetadataType::FRAMEWORK_TUNER,
671 AudioEncapsulationMetadataType::DVB_AD_DESCRIPTOR));
672
673 class AudioGainModeRoundTripTest : public testing::TestWithParam<AudioGainMode> {};
TEST_P(AudioGainModeRoundTripTest,Aidl2Legacy2Aidl)674 TEST_P(AudioGainModeRoundTripTest, Aidl2Legacy2Aidl) {
675 const auto initial = GetParam();
676 auto conv = aidl2legacy_AudioGainMode_audio_gain_mode_t(initial);
677 ASSERT_TRUE(conv.ok());
678 auto convBack = legacy2aidl_audio_gain_mode_t_AudioGainMode(conv.value());
679 ASSERT_TRUE(convBack.ok());
680 EXPECT_EQ(initial, convBack.value());
681 }
682 INSTANTIATE_TEST_SUITE_P(AudioGainMode, AudioGainModeRoundTripTest,
683 testing::Values(AudioGainMode::JOINT, AudioGainMode::CHANNELS,
684 AudioGainMode::RAMP));
685
TEST(AudioTrackSecondaryOutputInfoRoundTripTest,Aidl2Legacy2Aidl)686 TEST(AudioTrackSecondaryOutputInfoRoundTripTest, Aidl2Legacy2Aidl) {
687 const auto initial = make_TrackSecondaryOutputInfo();
688 auto conv = aidl2legacy_TrackSecondaryOutputInfo_TrackSecondaryOutputInfoPair(initial);
689 ASSERT_TRUE(conv.ok());
690 auto convBack = legacy2aidl_TrackSecondaryOutputInfoPair_TrackSecondaryOutputInfo(conv.value());
691 ASSERT_TRUE(convBack.ok());
692 EXPECT_EQ(initial, convBack.value());
693 }
694
695 using ExtraAudioDescriptorParam = std::tuple<AudioStandard, AudioEncapsulationType>;
696 class ExtraAudioDescriptorRoundTripTest : public testing::TestWithParam<ExtraAudioDescriptorParam> {
697 };
TEST_P(ExtraAudioDescriptorRoundTripTest,Aidl2Legacy2Aidl)698 TEST_P(ExtraAudioDescriptorRoundTripTest, Aidl2Legacy2Aidl) {
699 ExtraAudioDescriptor initial =
700 make_ExtraAudioDescriptor(std::get<0>(GetParam()), std::get<1>(GetParam()));
701 auto conv = aidl2legacy_ExtraAudioDescriptor_audio_extra_audio_descriptor(initial);
702 ASSERT_TRUE(conv.ok());
703 auto convBack = legacy2aidl_audio_extra_audio_descriptor_ExtraAudioDescriptor(conv.value());
704 ASSERT_TRUE(convBack.ok());
705 EXPECT_EQ(initial, convBack.value());
706 }
707
708 INSTANTIATE_TEST_SUITE_P(
709 ExtraAudioDescriptor, ExtraAudioDescriptorRoundTripTest,
710 testing::Values(std::make_tuple(AudioStandard::NONE, AudioEncapsulationType::NONE),
711 std::make_tuple(AudioStandard::EDID, AudioEncapsulationType::NONE),
712 std::make_tuple(AudioStandard::EDID, AudioEncapsulationType::IEC61937),
713 std::make_tuple(AudioStandard::SADB, AudioEncapsulationType::NONE),
714 std::make_tuple(AudioStandard::SADB, AudioEncapsulationType::IEC61937),
715 std::make_tuple(AudioStandard::VSADB, AudioEncapsulationType::NONE),
716 std::make_tuple(AudioStandard::VSADB, AudioEncapsulationType::IEC61937)));
717
TEST(AudioPortSessionExtRoundTripTest,Aidl2Legacy2Aidl)718 TEST(AudioPortSessionExtRoundTripTest, Aidl2Legacy2Aidl) {
719 const int32_t initial = 7;
720 auto conv = aidl2legacy_int32_t_audio_port_session_ext(initial);
721 ASSERT_TRUE(conv.ok());
722 auto convBack = legacy2aidl_audio_port_session_ext_int32_t(conv.value());
723 ASSERT_TRUE(convBack.ok());
724 EXPECT_EQ(initial, convBack.value());
725 }
726
727 class AudioGainTest : public testing::TestWithParam<bool> {};
TEST_P(AudioGainTest,Legacy2Aidl2Legacy)728 TEST_P(AudioGainTest, Legacy2Aidl2Legacy) {
729 audio_port_v7 port;
730 port.num_gains = 2;
731 port.gains[0] = {.mode = AUDIO_GAIN_MODE_JOINT,
732 .channel_mask = AUDIO_CHANNEL_IN_STEREO,
733 .min_value = -3200,
734 .max_value = 600,
735 .default_value = 0,
736 .step_value = 100,
737 .min_ramp_ms = 10,
738 .max_ramp_ms = 20};
739 port.gains[1] = {.mode = AUDIO_GAIN_MODE_JOINT,
740 .channel_mask = AUDIO_CHANNEL_IN_MONO,
741 .min_value = -8800,
742 .max_value = 4000,
743 .default_value = 0,
744 .step_value = 100,
745 .min_ramp_ms = 192,
746 .max_ramp_ms = 224};
747
748 const auto isInput = GetParam();
749 for (int i = 0; i < port.num_gains; i++) {
750 auto initial = port.gains[i];
751 auto conv = legacy2aidl_audio_gain_AudioGain(initial, isInput);
752 ASSERT_TRUE(conv.ok());
753 auto convBack = aidl2legacy_AudioGain_audio_gain(conv.value(), isInput);
754 ASSERT_TRUE(convBack.ok());
755 EXPECT_EQ(initial.mode, convBack.value().mode);
756 EXPECT_EQ(initial.channel_mask, convBack.value().channel_mask);
757 EXPECT_EQ(initial.min_value, convBack.value().min_value);
758 EXPECT_EQ(initial.max_value, convBack.value().max_value);
759 EXPECT_EQ(initial.default_value, convBack.value().default_value);
760 EXPECT_EQ(initial.step_value, convBack.value().step_value);
761 EXPECT_EQ(initial.min_ramp_ms, convBack.value().min_ramp_ms);
762 EXPECT_EQ(initial.max_ramp_ms, convBack.value().max_ramp_ms);
763 }
764 }
765 INSTANTIATE_TEST_SUITE_P(AudioGain, AudioGainTest, testing::Values(true, false));
766
TEST(AudioMicrophoneInfoFw,Aidl2Legacy2Aidl)767 TEST(AudioMicrophoneInfoFw, Aidl2Legacy2Aidl) {
768 media::MicrophoneInfoFw initial{};
769 // HALs must return at least 1 element in channelMapping. The zero value is 'UNUSED'.
770 initial.dynamic.channelMapping.resize(1);
771 auto conv = aidl2legacy_MicrophoneInfoFw_audio_microphone_characteristic_t(initial);
772 ASSERT_TRUE(conv.ok());
773 auto convBack = legacy2aidl_audio_microphone_characteristic_t_MicrophoneInfoFw(conv.value());
774 ASSERT_TRUE(convBack.ok());
775 EXPECT_EQ(initial, convBack.value());
776 }
777
TEST(AudioMicrophoneInfoFw,UnknownValues)778 TEST(AudioMicrophoneInfoFw, UnknownValues) {
779 {
780 media::MicrophoneInfoFw initial;
781 initial.dynamic.channelMapping.resize(1);
782 initial.info.indexInTheGroup = MicrophoneInfo::INDEX_IN_THE_GROUP_UNKNOWN;
783 auto conv = aidl2legacy_MicrophoneInfoFw_audio_microphone_characteristic_t(initial);
784 ASSERT_TRUE(conv.ok());
785 auto convBack =
786 legacy2aidl_audio_microphone_characteristic_t_MicrophoneInfoFw(conv.value());
787 ASSERT_TRUE(convBack.ok());
788 EXPECT_EQ(initial, convBack.value());
789 }
790 for (const auto f : {&audio_microphone_characteristic_t::sensitivity,
791 &audio_microphone_characteristic_t::max_spl,
792 &audio_microphone_characteristic_t::min_spl}) {
793 audio_microphone_characteristic_t mic{};
794 if (f == &audio_microphone_characteristic_t::sensitivity) {
795 mic.*f = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
796 } else {
797 mic.*f = AUDIO_MICROPHONE_SPL_UNKNOWN;
798 }
799 auto aidl = legacy2aidl_audio_microphone_characteristic_t_MicrophoneInfoFw(mic);
800 ASSERT_TRUE(aidl.ok());
801 EXPECT_FALSE(aidl.value().info.sensitivity.has_value());
802 }
803 for (const auto f : {&audio_microphone_characteristic_t::geometric_location,
804 &audio_microphone_characteristic_t::orientation}) {
805 for (const auto c : {&audio_microphone_coordinate::x, &audio_microphone_coordinate::y,
806 &audio_microphone_coordinate::z}) {
807 audio_microphone_characteristic_t mic{};
808 mic.*f.*c = AUDIO_MICROPHONE_COORDINATE_UNKNOWN;
809 auto conv = legacy2aidl_audio_microphone_characteristic_t_MicrophoneInfoFw(mic);
810 ASSERT_TRUE(conv.ok());
811 const auto& aidl = conv.value();
812 if (f == &audio_microphone_characteristic_t::geometric_location) {
813 EXPECT_FALSE(aidl.info.position.has_value());
814 EXPECT_TRUE(aidl.info.orientation.has_value());
815 } else {
816 EXPECT_TRUE(aidl.info.position.has_value());
817 EXPECT_FALSE(aidl.info.orientation.has_value());
818 }
819 }
820 }
821 }
822
TEST(AudioMicrophoneInfoFw,ChannelMapping)823 TEST(AudioMicrophoneInfoFw, ChannelMapping) {
824 audio_microphone_characteristic_t mic{};
825 mic.channel_mapping[1] = AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT;
826 mic.channel_mapping[3] = AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED;
827 auto conv = legacy2aidl_audio_microphone_characteristic_t_MicrophoneInfoFw(mic);
828 ASSERT_TRUE(conv.ok());
829 const auto& aidl = conv.value();
830 EXPECT_EQ(4, aidl.dynamic.channelMapping.size());
831 EXPECT_EQ(MicrophoneDynamicInfo::ChannelMapping::UNUSED, aidl.dynamic.channelMapping[0]);
832 EXPECT_EQ(MicrophoneDynamicInfo::ChannelMapping::DIRECT, aidl.dynamic.channelMapping[1]);
833 EXPECT_EQ(MicrophoneDynamicInfo::ChannelMapping::UNUSED, aidl.dynamic.channelMapping[2]);
834 EXPECT_EQ(MicrophoneDynamicInfo::ChannelMapping::PROCESSED, aidl.dynamic.channelMapping[3]);
835 }
836
TEST(AudioInputFlags,Aidl2Legacy2Aidl)837 TEST(AudioInputFlags, Aidl2Legacy2Aidl) {
838 for (auto flag : enum_range<AudioInputFlags>()) {
839 int32_t aidlMask = 1 << static_cast<int32_t>(flag);
840 auto convMask = aidl2legacy_int32_t_audio_input_flags_t_mask(aidlMask);
841 ASSERT_TRUE(convMask.ok());
842 ASSERT_EQ(1, __builtin_popcount(convMask.value()));
843 auto convFlag = legacy2aidl_audio_input_flags_t_AudioInputFlags(convMask.value());
844 ASSERT_TRUE(convFlag.ok());
845 EXPECT_EQ(flag, convFlag.value());
846 }
847 }
848
TEST(AudioOutputFlags,Aidl2Legacy2Aidl)849 TEST(AudioOutputFlags, Aidl2Legacy2Aidl) {
850 for (auto flag : enum_range<AudioOutputFlags>()) {
851 int32_t aidlMask = 1 << static_cast<int32_t>(flag);
852 auto convMask = aidl2legacy_int32_t_audio_output_flags_t_mask(aidlMask);
853 ASSERT_TRUE(convMask.ok());
854 ASSERT_EQ(1, __builtin_popcount(convMask.value()));
855 auto convFlag = legacy2aidl_audio_output_flags_t_AudioOutputFlags(convMask.value());
856 ASSERT_TRUE(convFlag.ok());
857 EXPECT_EQ(flag, convFlag.value());
858 }
859 }
860