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 package android.media.audio.cts; 18 19 import android.media.AudioDescriptor; 20 import android.media.AudioProfile; 21 import android.os.Parcel; 22 23 import com.android.compatibility.common.util.CtsAndroidTestCase; 24 25 import java.util.Arrays; 26 27 public class AudioDescriptorTest extends CtsAndroidTestCase { 28 // ----------------------------------------------------------------- 29 // AUDIODESCRIPTOR TESTS: 30 // ---------------------------------- 31 32 // ----------------------------------------------------------------- 33 // Parcelable tests 34 // ---------------------------------- 35 36 // Test case 1: call describeContents(), not used yet, but needs to be exercised testParcelableDescribeContents()37 public void testParcelableDescribeContents() throws Exception { 38 final AudioDescriptor ad = new AudioDescriptor(AudioDescriptor.STANDARD_EDID, 39 AudioProfile.AUDIO_ENCAPSULATION_TYPE_IEC61937, new byte[]{0x0F, 0x18, 0x4A}); 40 assertNotNull("Failure to create the AudioDescriptor", ad); 41 assertEquals(0, ad.describeContents()); 42 } 43 44 // Test case 2: create an instance, marshall it and create a new instance, 45 // check for equality, both by comparing fields, and with the equals(Object) method testParcelableWriteToParcelCreate()46 public void testParcelableWriteToParcelCreate() throws Exception { 47 final AudioDescriptor srcDescr = new AudioDescriptor(AudioDescriptor.STANDARD_EDID, 48 AudioProfile.AUDIO_ENCAPSULATION_TYPE_IEC61937, new byte[]{0x0F, 0x18, 0x4A}); 49 final Parcel srcParcel = Parcel.obtain(); 50 final Parcel dstParcel = Parcel.obtain(); 51 final byte[] mbytes; 52 53 srcDescr.writeToParcel(srcParcel, 0); 54 mbytes = srcParcel.marshall(); 55 dstParcel.unmarshall(mbytes, 0, mbytes.length); 56 dstParcel.setDataPosition(0); 57 final AudioDescriptor targetDescr = AudioDescriptor.CREATOR.createFromParcel(dstParcel); 58 assertEquals("Marshalled/restored standard doesn't match", 59 srcDescr.getStandard(), targetDescr.getStandard()); 60 assertTrue("Marshalled/restored descriptor doesn't match", 61 Arrays.equals(srcDescr.getDescriptor(), targetDescr.getDescriptor())); 62 assertEquals("Marshalled/restored encapsulation type don't match", 63 srcDescr.getEncapsulationType(), targetDescr.getEncapsulationType()); 64 assertTrue("Source and target AudioDescriptors are not considered equal", 65 srcDescr.equals(targetDescr)); 66 } 67 } 68