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.cts; 18 19 import static org.junit.Assert.assertNotEquals; 20 21 import android.icu.util.ULocale; 22 import android.media.AudioPresentation; 23 import android.util.Log; 24 25 import com.android.compatibility.common.util.CtsAndroidTestCase; 26 27 import java.util.HashMap; 28 import java.util.Locale; 29 import java.util.Map; 30 31 public class AudioPresentationTest extends CtsAndroidTestCase { 32 private String TAG = "AudioPresentationTest"; 33 private static final String REPORT_LOG_NAME = "CtsMediaTestCases"; 34 testGetters()35 public void testGetters() throws Exception { 36 final int PRESENTATION_ID = 42; 37 final int PROGRAM_ID = 43; 38 final Map<Locale, CharSequence> LABELS = generateLabels(); 39 final Locale LOCALE = Locale.US; 40 final int MASTERING_INDICATION = AudioPresentation.MASTERED_FOR_STEREO; 41 final boolean HAS_AUDIO_DESCRIPTION = false; 42 final boolean HAS_SPOKEN_SUBTITLES = true; 43 final boolean HAS_DIALOGUE_ENHANCEMENT = true; 44 45 AudioPresentation presentation = (new AudioPresentation.Builder(PRESENTATION_ID) 46 .setProgramId(PROGRAM_ID) 47 .setLocale(ULocale.forLocale(LOCALE)) 48 .setLabels(localeToULocale(LABELS)) 49 .setMasteringIndication(MASTERING_INDICATION) 50 .setHasAudioDescription(HAS_AUDIO_DESCRIPTION) 51 .setHasSpokenSubtitles(HAS_SPOKEN_SUBTITLES) 52 .setHasDialogueEnhancement(HAS_DIALOGUE_ENHANCEMENT)).build(); 53 assertEquals(PRESENTATION_ID, presentation.getPresentationId()); 54 assertEquals(PROGRAM_ID, presentation.getProgramId()); 55 assertEquals(LABELS, presentation.getLabels()); 56 assertEquals(LOCALE, presentation.getLocale()); 57 assertEquals(MASTERING_INDICATION, presentation.getMasteringIndication()); 58 assertEquals(HAS_AUDIO_DESCRIPTION, presentation.hasAudioDescription()); 59 assertEquals(HAS_SPOKEN_SUBTITLES, presentation.hasSpokenSubtitles()); 60 assertEquals(HAS_DIALOGUE_ENHANCEMENT, presentation.hasDialogueEnhancement()); 61 } 62 testEqualsAndHashCode()63 public void testEqualsAndHashCode() throws Exception { 64 final int PRESENTATION_ID = 42; 65 final int PROGRAM_ID = 43; 66 final Map<Locale, CharSequence> LABELS = generateLabels(); 67 final Locale LOCALE = Locale.US; 68 final Locale LOCALE_3 = Locale.FRENCH; 69 final int MASTERING_INDICATION = AudioPresentation.MASTERED_FOR_STEREO; 70 final int MASTERING_INDICATION_3 = AudioPresentation.MASTERED_FOR_HEADPHONE; 71 final boolean HAS_AUDIO_DESCRIPTION = false; 72 final boolean HAS_SPOKEN_SUBTITLES = true; 73 final boolean HAS_DIALOGUE_ENHANCEMENT = true; 74 75 { 76 AudioPresentation presentation1 = (new AudioPresentation.Builder(PRESENTATION_ID)) 77 .build(); 78 assertEquals(presentation1, presentation1); 79 assertNotEquals(presentation1, null); 80 assertNotEquals(presentation1, new Object()); 81 AudioPresentation presentation2 = (new AudioPresentation.Builder(PRESENTATION_ID)) 82 .build(); 83 assertEquals(presentation1, presentation2); 84 assertEquals(presentation2, presentation1); 85 assertEquals(presentation1.hashCode(), presentation2.hashCode()); 86 AudioPresentation presentation3 = (new AudioPresentation.Builder(PRESENTATION_ID + 1)) 87 .build(); 88 assertNotEquals(presentation1, presentation3); 89 assertNotEquals(presentation1.hashCode(), presentation3.hashCode()); 90 } 91 { 92 AudioPresentation presentation1 = (new AudioPresentation.Builder(PRESENTATION_ID) 93 .setProgramId(PROGRAM_ID)).build(); 94 AudioPresentation presentation2 = (new AudioPresentation.Builder(PRESENTATION_ID) 95 .setProgramId(PROGRAM_ID)).build(); 96 assertEquals(presentation1, presentation2); 97 assertEquals(presentation2, presentation1); 98 assertEquals(presentation1.hashCode(), presentation2.hashCode()); 99 AudioPresentation presentation3 = (new AudioPresentation.Builder(PRESENTATION_ID) 100 .setProgramId(PROGRAM_ID + 1)).build(); 101 assertNotEquals(presentation1, presentation3); 102 assertNotEquals(presentation1.hashCode(), presentation3.hashCode()); 103 } 104 { 105 AudioPresentation presentation1 = (new AudioPresentation.Builder(PRESENTATION_ID) 106 .setLocale(ULocale.forLocale(LOCALE))).build(); 107 AudioPresentation presentation2 = (new AudioPresentation.Builder(PRESENTATION_ID) 108 .setLocale(ULocale.forLocale(LOCALE))).build(); 109 assertEquals(presentation1, presentation2); 110 assertEquals(presentation2, presentation1); 111 assertEquals(presentation1.hashCode(), presentation2.hashCode()); 112 AudioPresentation presentation3 = (new AudioPresentation.Builder(PRESENTATION_ID) 113 .setLocale(ULocale.forLocale(LOCALE_3))).build(); 114 assertNotEquals(presentation1, presentation3); 115 assertNotEquals(presentation1.hashCode(), presentation3.hashCode()); 116 } 117 { 118 AudioPresentation presentation1 = (new AudioPresentation.Builder(PRESENTATION_ID) 119 .setLabels(localeToULocale(LABELS))).build(); 120 AudioPresentation presentation2 = (new AudioPresentation.Builder(PRESENTATION_ID) 121 .setLabels(localeToULocale(LABELS))).build(); 122 assertEquals(presentation1, presentation2); 123 assertEquals(presentation2, presentation1); 124 assertEquals(presentation1.hashCode(), presentation2.hashCode()); 125 AudioPresentation presentation3 = (new AudioPresentation.Builder(PRESENTATION_ID) 126 .setLabels(new HashMap<ULocale, CharSequence>())).build(); 127 assertNotEquals(presentation1, presentation3); 128 assertNotEquals(presentation1.hashCode(), presentation3.hashCode()); 129 } 130 { 131 AudioPresentation presentation1 = (new AudioPresentation.Builder(PRESENTATION_ID) 132 .setMasteringIndication(MASTERING_INDICATION)).build(); 133 AudioPresentation presentation2 = (new AudioPresentation.Builder(PRESENTATION_ID) 134 .setMasteringIndication(MASTERING_INDICATION)).build(); 135 assertEquals(presentation1, presentation2); 136 assertEquals(presentation2, presentation1); 137 assertEquals(presentation1.hashCode(), presentation2.hashCode()); 138 AudioPresentation presentation3 = (new AudioPresentation.Builder(PRESENTATION_ID) 139 .setMasteringIndication(MASTERING_INDICATION_3)).build(); 140 assertNotEquals(presentation1, presentation3); 141 assertNotEquals(presentation1.hashCode(), presentation3.hashCode()); 142 } 143 { 144 AudioPresentation presentation1 = (new AudioPresentation.Builder(PRESENTATION_ID) 145 .setHasAudioDescription(HAS_AUDIO_DESCRIPTION)).build(); 146 AudioPresentation presentation2 = (new AudioPresentation.Builder(PRESENTATION_ID) 147 .setHasAudioDescription(HAS_AUDIO_DESCRIPTION)).build(); 148 assertEquals(presentation1, presentation2); 149 assertEquals(presentation2, presentation1); 150 assertEquals(presentation1.hashCode(), presentation2.hashCode()); 151 AudioPresentation presentation3 = (new AudioPresentation.Builder(PRESENTATION_ID) 152 .setHasAudioDescription(!HAS_AUDIO_DESCRIPTION)).build(); 153 assertNotEquals(presentation1, presentation3); 154 assertNotEquals(presentation1.hashCode(), presentation3.hashCode()); 155 } 156 { 157 AudioPresentation presentation1 = (new AudioPresentation.Builder(PRESENTATION_ID) 158 .setHasSpokenSubtitles(HAS_SPOKEN_SUBTITLES)).build(); 159 AudioPresentation presentation2 = (new AudioPresentation.Builder(PRESENTATION_ID) 160 .setHasSpokenSubtitles(HAS_SPOKEN_SUBTITLES)).build(); 161 assertEquals(presentation1, presentation2); 162 assertEquals(presentation2, presentation1); 163 assertEquals(presentation1.hashCode(), presentation2.hashCode()); 164 AudioPresentation presentation3 = (new AudioPresentation.Builder(PRESENTATION_ID) 165 .setHasSpokenSubtitles(!HAS_SPOKEN_SUBTITLES)).build(); 166 assertNotEquals(presentation1, presentation3); 167 assertNotEquals(presentation1.hashCode(), presentation3.hashCode()); 168 } 169 { 170 AudioPresentation presentation1 = (new AudioPresentation.Builder(PRESENTATION_ID) 171 .setHasDialogueEnhancement(HAS_DIALOGUE_ENHANCEMENT)).build(); 172 AudioPresentation presentation2 = (new AudioPresentation.Builder(PRESENTATION_ID) 173 .setHasDialogueEnhancement(HAS_DIALOGUE_ENHANCEMENT)).build(); 174 assertEquals(presentation1, presentation2); 175 assertEquals(presentation2, presentation1); 176 assertEquals(presentation1.hashCode(), presentation2.hashCode()); 177 AudioPresentation presentation3 = (new AudioPresentation.Builder(PRESENTATION_ID) 178 .setHasDialogueEnhancement(!HAS_DIALOGUE_ENHANCEMENT)).build(); 179 assertNotEquals(presentation1, presentation3); 180 assertNotEquals(presentation1.hashCode(), presentation3.hashCode()); 181 } 182 } 183 generateLabels()184 private static Map<Locale, CharSequence> generateLabels() { 185 Map<Locale, CharSequence> result = new HashMap<Locale, CharSequence>(); 186 result.put(Locale.US, Locale.US.getDisplayLanguage()); 187 result.put(Locale.FRENCH, Locale.FRENCH.getDisplayLanguage()); 188 result.put(Locale.GERMAN, Locale.GERMAN.getDisplayLanguage()); 189 return result; 190 } 191 localeToULocale(Map<Locale, CharSequence> locales)192 private static Map<ULocale, CharSequence> localeToULocale(Map<Locale, CharSequence> locales) { 193 Map<ULocale, CharSequence> ulocaleLabels = new HashMap<ULocale, CharSequence>(); 194 for (Map.Entry<Locale, CharSequence> entry : locales.entrySet()) { 195 ulocaleLabels.put(ULocale.forLocale(entry.getKey()), entry.getValue()); 196 } 197 return ulocaleLabels; 198 } 199 } 200