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 android.media.AudioPresentation;
20 import android.util.Log;
21 
22 import com.android.compatibility.common.util.CtsAndroidTestCase;
23 
24 import java.util.HashMap;
25 import java.util.Locale;
26 import java.util.Map;
27 
28 public class AudioPresentationTest extends CtsAndroidTestCase {
29     private String TAG = "AudioPresentationTest";
30     private static final String REPORT_LOG_NAME = "CtsMediaTestCases";
31 
testGetters()32     public void testGetters() throws Exception {
33         final int PRESENTATION_ID = 42;
34         final int PROGRAM_ID = 43;
35         final Map<Locale, String> LABELS = generateLabels();
36         final Locale LOCALE = Locale.US;
37         final int MASTERING_INDICATION = AudioPresentation.MASTERED_FOR_STEREO;
38         final boolean HAS_AUDIO_DESCRIPTION = false;
39         final boolean HAS_SPOKEN_SUBTITLES = true;
40         final boolean HAS_DIALOGUE_ENHANCEMENT = true;
41 
42         AudioPresentation presentation = new AudioPresentation(
43                 PRESENTATION_ID,
44                 PROGRAM_ID,
45                 labelsLocaleToString(LABELS),
46                 LOCALE.toString(),
47                 MASTERING_INDICATION,
48                 HAS_AUDIO_DESCRIPTION,
49                 HAS_SPOKEN_SUBTITLES,
50                 HAS_DIALOGUE_ENHANCEMENT);
51         assertEquals(PRESENTATION_ID, presentation.getPresentationId());
52         assertEquals(PROGRAM_ID, presentation.getProgramId());
53         assertEquals(LABELS.toString().toLowerCase(),
54                 presentation.getLabels().toString().toLowerCase());
55         assertEquals(LOCALE.toString().toLowerCase(),
56                 presentation.getLocale().toString().toLowerCase());
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 
generateLabels()63     private static Map<Locale, String> generateLabels() {
64         Map<Locale, String> result = new HashMap<Locale, String>();
65         result.put(Locale.US, Locale.US.getDisplayLanguage());
66         result.put(Locale.FRENCH, Locale.FRENCH.getDisplayLanguage());
67         result.put(Locale.GERMAN, Locale.GERMAN.getDisplayLanguage());
68         return result;
69     }
70 
labelsLocaleToString(Map<Locale, String> localesMap)71     private static Map<String, String> labelsLocaleToString(Map<Locale, String> localesMap) {
72         Map<String, String> result = new HashMap<String, String>();
73         for (Map.Entry<Locale, String> entry : localesMap.entrySet()) {
74             result.put(entry.getKey().toString(), entry.getValue());
75         }
76         return result;
77     }
78 }
79