1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.media.audio.cts; 18 19 import static org.junit.Assert.assertNotEquals; 20 21 import android.icu.util.ULocale; 22 import android.media.AudioPresentation; 23 import android.media.cts.NonMediaMainlineTest; 24 import android.util.Log; 25 26 import com.android.compatibility.common.util.CtsAndroidTestCase; 27 28 import java.util.HashMap; 29 import java.util.Locale; 30 import java.util.Map; 31 32 @NonMediaMainlineTest 33 public class AudioPresentationTest extends CtsAndroidTestCase { 34 private String TAG = "AudioPresentationTest"; 35 private static final String REPORT_LOG_NAME = "CtsMediaAudioTestCases"; 36 testGetters()37 public void testGetters() throws Exception { 38 final int PRESENTATION_ID = 42; 39 final int PROGRAM_ID = 43; 40 final Map<Locale, CharSequence> LABELS = generateLabels(); 41 final Locale LOCALE = Locale.US; 42 final int MASTERING_INDICATION = AudioPresentation.MASTERED_FOR_STEREO; 43 final boolean HAS_AUDIO_DESCRIPTION = false; 44 final boolean HAS_SPOKEN_SUBTITLES = true; 45 final boolean HAS_DIALOGUE_ENHANCEMENT = true; 46 47 AudioPresentation presentation = (new AudioPresentation.Builder(PRESENTATION_ID) 48 .setProgramId(PROGRAM_ID) 49 .setLocale(ULocale.forLocale(LOCALE)) 50 .setLabels(localeToULocale(LABELS)) 51 .setMasteringIndication(MASTERING_INDICATION) 52 .setHasAudioDescription(HAS_AUDIO_DESCRIPTION) 53 .setHasSpokenSubtitles(HAS_SPOKEN_SUBTITLES) 54 .setHasDialogueEnhancement(HAS_DIALOGUE_ENHANCEMENT)).build(); 55 assertEquals(PRESENTATION_ID, presentation.getPresentationId()); 56 assertEquals(PROGRAM_ID, presentation.getProgramId()); 57 assertEquals(LABELS, presentation.getLabels()); 58 assertEquals(LOCALE, presentation.getLocale()); 59 assertEquals(MASTERING_INDICATION, presentation.getMasteringIndication()); 60 assertEquals(HAS_AUDIO_DESCRIPTION, presentation.hasAudioDescription()); 61 assertEquals(HAS_SPOKEN_SUBTITLES, presentation.hasSpokenSubtitles()); 62 assertEquals(HAS_DIALOGUE_ENHANCEMENT, presentation.hasDialogueEnhancement()); 63 } 64 testEqualsAndHashCode()65 public void testEqualsAndHashCode() throws Exception { 66 final int PRESENTATION_ID = 42; 67 final int PROGRAM_ID = 43; 68 final Map<Locale, CharSequence> LABELS = generateLabels(); 69 final Locale LOCALE = Locale.US; 70 final Locale LOCALE_3 = Locale.FRENCH; 71 final int MASTERING_INDICATION = AudioPresentation.MASTERED_FOR_STEREO; 72 final int MASTERING_INDICATION_3 = AudioPresentation.MASTERED_FOR_HEADPHONE; 73 final boolean HAS_AUDIO_DESCRIPTION = false; 74 final boolean HAS_SPOKEN_SUBTITLES = true; 75 final boolean HAS_DIALOGUE_ENHANCEMENT = true; 76 77 { 78 AudioPresentation presentation1 = (new AudioPresentation.Builder(PRESENTATION_ID)) 79 .build(); 80 assertEquals(presentation1, presentation1); 81 assertNotEquals(presentation1, null); 82 assertNotEquals(presentation1, new Object()); 83 AudioPresentation presentation2 = (new AudioPresentation.Builder(PRESENTATION_ID)) 84 .build(); 85 assertEquals(presentation1, presentation2); 86 assertEquals(presentation2, presentation1); 87 assertEquals(presentation1.hashCode(), presentation2.hashCode()); 88 AudioPresentation presentation3 = (new AudioPresentation.Builder(PRESENTATION_ID + 1)) 89 .build(); 90 assertNotEquals(presentation1, presentation3); 91 assertNotEquals(presentation1.hashCode(), presentation3.hashCode()); 92 } 93 { 94 AudioPresentation presentation1 = (new AudioPresentation.Builder(PRESENTATION_ID) 95 .setProgramId(PROGRAM_ID)).build(); 96 AudioPresentation presentation2 = (new AudioPresentation.Builder(PRESENTATION_ID) 97 .setProgramId(PROGRAM_ID)).build(); 98 assertEquals(presentation1, presentation2); 99 assertEquals(presentation2, presentation1); 100 assertEquals(presentation1.hashCode(), presentation2.hashCode()); 101 AudioPresentation presentation3 = (new AudioPresentation.Builder(PRESENTATION_ID) 102 .setProgramId(PROGRAM_ID + 1)).build(); 103 assertNotEquals(presentation1, presentation3); 104 assertNotEquals(presentation1.hashCode(), presentation3.hashCode()); 105 } 106 { 107 AudioPresentation presentation1 = (new AudioPresentation.Builder(PRESENTATION_ID) 108 .setLocale(ULocale.forLocale(LOCALE))).build(); 109 AudioPresentation presentation2 = (new AudioPresentation.Builder(PRESENTATION_ID) 110 .setLocale(ULocale.forLocale(LOCALE))).build(); 111 assertEquals(presentation1, presentation2); 112 assertEquals(presentation2, presentation1); 113 assertEquals(presentation1.hashCode(), presentation2.hashCode()); 114 AudioPresentation presentation3 = (new AudioPresentation.Builder(PRESENTATION_ID) 115 .setLocale(ULocale.forLocale(LOCALE_3))).build(); 116 assertNotEquals(presentation1, presentation3); 117 assertNotEquals(presentation1.hashCode(), presentation3.hashCode()); 118 } 119 { 120 AudioPresentation presentation1 = (new AudioPresentation.Builder(PRESENTATION_ID) 121 .setLabels(localeToULocale(LABELS))).build(); 122 AudioPresentation presentation2 = (new AudioPresentation.Builder(PRESENTATION_ID) 123 .setLabels(localeToULocale(LABELS))).build(); 124 assertEquals(presentation1, presentation2); 125 assertEquals(presentation2, presentation1); 126 assertEquals(presentation1.hashCode(), presentation2.hashCode()); 127 AudioPresentation presentation3 = (new AudioPresentation.Builder(PRESENTATION_ID) 128 .setLabels(new HashMap<ULocale, CharSequence>())).build(); 129 assertNotEquals(presentation1, presentation3); 130 assertNotEquals(presentation1.hashCode(), presentation3.hashCode()); 131 } 132 { 133 AudioPresentation presentation1 = (new AudioPresentation.Builder(PRESENTATION_ID) 134 .setMasteringIndication(MASTERING_INDICATION)).build(); 135 AudioPresentation presentation2 = (new AudioPresentation.Builder(PRESENTATION_ID) 136 .setMasteringIndication(MASTERING_INDICATION)).build(); 137 assertEquals(presentation1, presentation2); 138 assertEquals(presentation2, presentation1); 139 assertEquals(presentation1.hashCode(), presentation2.hashCode()); 140 AudioPresentation presentation3 = (new AudioPresentation.Builder(PRESENTATION_ID) 141 .setMasteringIndication(MASTERING_INDICATION_3)).build(); 142 assertNotEquals(presentation1, presentation3); 143 assertNotEquals(presentation1.hashCode(), presentation3.hashCode()); 144 } 145 { 146 AudioPresentation presentation1 = (new AudioPresentation.Builder(PRESENTATION_ID) 147 .setHasAudioDescription(HAS_AUDIO_DESCRIPTION)).build(); 148 AudioPresentation presentation2 = (new AudioPresentation.Builder(PRESENTATION_ID) 149 .setHasAudioDescription(HAS_AUDIO_DESCRIPTION)).build(); 150 assertEquals(presentation1, presentation2); 151 assertEquals(presentation2, presentation1); 152 assertEquals(presentation1.hashCode(), presentation2.hashCode()); 153 AudioPresentation presentation3 = (new AudioPresentation.Builder(PRESENTATION_ID) 154 .setHasAudioDescription(!HAS_AUDIO_DESCRIPTION)).build(); 155 assertNotEquals(presentation1, presentation3); 156 assertNotEquals(presentation1.hashCode(), presentation3.hashCode()); 157 } 158 { 159 AudioPresentation presentation1 = (new AudioPresentation.Builder(PRESENTATION_ID) 160 .setHasSpokenSubtitles(HAS_SPOKEN_SUBTITLES)).build(); 161 AudioPresentation presentation2 = (new AudioPresentation.Builder(PRESENTATION_ID) 162 .setHasSpokenSubtitles(HAS_SPOKEN_SUBTITLES)).build(); 163 assertEquals(presentation1, presentation2); 164 assertEquals(presentation2, presentation1); 165 assertEquals(presentation1.hashCode(), presentation2.hashCode()); 166 AudioPresentation presentation3 = (new AudioPresentation.Builder(PRESENTATION_ID) 167 .setHasSpokenSubtitles(!HAS_SPOKEN_SUBTITLES)).build(); 168 assertNotEquals(presentation1, presentation3); 169 assertNotEquals(presentation1.hashCode(), presentation3.hashCode()); 170 } 171 { 172 AudioPresentation presentation1 = (new AudioPresentation.Builder(PRESENTATION_ID) 173 .setHasDialogueEnhancement(HAS_DIALOGUE_ENHANCEMENT)).build(); 174 AudioPresentation presentation2 = (new AudioPresentation.Builder(PRESENTATION_ID) 175 .setHasDialogueEnhancement(HAS_DIALOGUE_ENHANCEMENT)).build(); 176 assertEquals(presentation1, presentation2); 177 assertEquals(presentation2, presentation1); 178 assertEquals(presentation1.hashCode(), presentation2.hashCode()); 179 AudioPresentation presentation3 = (new AudioPresentation.Builder(PRESENTATION_ID) 180 .setHasDialogueEnhancement(!HAS_DIALOGUE_ENHANCEMENT)).build(); 181 assertNotEquals(presentation1, presentation3); 182 assertNotEquals(presentation1.hashCode(), presentation3.hashCode()); 183 } 184 } 185 generateLabels()186 private static Map<Locale, CharSequence> generateLabels() { 187 Map<Locale, CharSequence> result = new HashMap<Locale, CharSequence>(); 188 result.put(Locale.US, Locale.US.getDisplayLanguage()); 189 result.put(Locale.FRENCH, Locale.FRENCH.getDisplayLanguage()); 190 result.put(Locale.GERMAN, Locale.GERMAN.getDisplayLanguage()); 191 return result; 192 } 193 localeToULocale(Map<Locale, CharSequence> locales)194 private static Map<ULocale, CharSequence> localeToULocale(Map<Locale, CharSequence> locales) { 195 Map<ULocale, CharSequence> ulocaleLabels = new HashMap<ULocale, CharSequence>(); 196 for (Map.Entry<Locale, CharSequence> entry : locales.entrySet()) { 197 ulocaleLabels.put(ULocale.forLocale(entry.getKey()), entry.getValue()); 198 } 199 return ulocaleLabels; 200 } 201 } 202