1 /* 2 * Copyright (C) 2015 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 package com.android.tv.util; 17 18 import static com.android.tv.util.TvTrackInfoUtils.getBestTrackInfo; 19 20 import android.media.tv.TvTrackInfo; 21 import android.test.suitebuilder.annotation.SmallTest; 22 23 import com.android.tv.testing.ComparatorTester; 24 25 import junit.framework.TestCase; 26 27 import java.util.Arrays; 28 import java.util.Collections; 29 import java.util.Comparator; 30 import java.util.List; 31 32 /** 33 * Tests for {@link com.android.tv.util.TvTrackInfoUtils}. 34 */ 35 @SmallTest 36 public class TvTrackInfoUtilsTest extends TestCase { 37 38 private static final String UN_MATCHED_ID = "no matching ID"; 39 40 private static final TvTrackInfo INFO_1_EN_1 = create("1", "en", 1); 41 42 private static final TvTrackInfo INFO_2_EN_5 = create("2", "en", 5); 43 44 private static final TvTrackInfo INFO_3_FR_5 = create("3", "fr", 5); 45 create(String id, String fr, int audioChannelCount)46 private static TvTrackInfo create(String id, String fr, int audioChannelCount) { 47 return new TvTrackInfo.Builder(TvTrackInfo.TYPE_AUDIO, id) 48 .setLanguage(fr) 49 .setAudioChannelCount(audioChannelCount) 50 .build(); 51 } 52 53 private static final List<TvTrackInfo> ALL = Arrays.asList(INFO_1_EN_1, INFO_2_EN_5, INFO_3_FR_5); 54 testGetBestTrackInfo_empty()55 public void testGetBestTrackInfo_empty() { 56 TvTrackInfo result = getBestTrackInfo(Collections.<TvTrackInfo>emptyList(), 57 UN_MATCHED_ID, "en", 1); 58 assertEquals("best track ", null, result); 59 } 60 testGetBestTrackInfo_exactMatch()61 public void testGetBestTrackInfo_exactMatch() { 62 TvTrackInfo result = getBestTrackInfo(ALL, "1", "en", 1); 63 assertEquals("best track ", INFO_1_EN_1, result); 64 } 65 testGetBestTrackInfo_langAndChannelCountMatch()66 public void testGetBestTrackInfo_langAndChannelCountMatch() { 67 TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, "en", 5); 68 assertEquals("best track ", INFO_2_EN_5, result); 69 } 70 testGetBestTrackInfo_languageOnlyMatch()71 public void testGetBestTrackInfo_languageOnlyMatch() { 72 TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, "fr", 1); 73 assertEquals("best track ", INFO_3_FR_5, result); 74 } 75 testGetBestTrackInfo_noMatches()76 public void testGetBestTrackInfo_noMatches() { 77 TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, "kr", 1); 78 assertEquals("best track ", INFO_1_EN_1, result); 79 } 80 81 testComparator()82 public void testComparator() { 83 Comparator<TvTrackInfo> comparator = TvTrackInfoUtils.createComparator("1", "en", 1); 84 ComparatorTester.withoutEqualsTest(comparator) 85 // lang not match 86 .addComparableGroup(create("1", "kr", 1), create("2", "kr", 2), 87 create("1", "ja", 1), 88 create("1", "ch", 1)) 89 // lang match not count match 90 .addComparableGroup(create("2", "en", 2), create("3", "en", 3), 91 create("1", "en", 2)) 92 // lang and count match 93 .addComparableGroup(create("2", "en", 1), create("3", "en", 1)) 94 // all match 95 .addComparableGroup(create("1", "en", 1), create("1", "en", 1)) 96 .test(); 97 } 98 } 99