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 17 package com.android.tv.data; 18 19 import static android.support.test.InstrumentationRegistry.getTargetContext; 20 import static org.junit.Assert.assertEquals; 21 import static org.junit.Assert.assertNotNull; 22 import static org.junit.Assert.assertNull; 23 import static org.junit.Assert.assertTrue; 24 25 import android.media.tv.TvContract.Programs.Genres; 26 import android.os.Build; 27 import android.support.test.filters.SmallTest; 28 29 import org.junit.Test; 30 31 /** 32 * Tests for {@link Channel}. 33 */ 34 @SmallTest 35 public class GenreItemTest { 36 private static final String INVALID_GENRE = "INVALID GENRE"; 37 38 @Test 39 public void testGetLabels() { 40 // Checks if no exception is thrown. 41 GenreItems.getLabels(getTargetContext()); 42 } 43 44 @Test 45 public void testGetCanonicalGenre() { 46 int count = GenreItems.getGenreCount(); 47 assertNull(GenreItems.getCanonicalGenre(GenreItems.ID_ALL_CHANNELS)); 48 for (int i = 1; i < count; ++i) { 49 assertNotNull(GenreItems.getCanonicalGenre(i)); 50 } 51 } 52 53 @Test 54 public void testGetId_base() { 55 int count = GenreItems.getGenreCount(); 56 assertEquals(GenreItems.ID_ALL_CHANNELS, GenreItems.getId(null)); 57 assertEquals(GenreItems.ID_ALL_CHANNELS, GenreItems.getId(INVALID_GENRE)); 58 assertInRange(GenreItems.getId(Genres.FAMILY_KIDS), 1, count - 1); 59 assertInRange(GenreItems.getId(Genres.SPORTS), 1, count - 1); 60 assertInRange(GenreItems.getId(Genres.SHOPPING), 1, count - 1); 61 assertInRange(GenreItems.getId(Genres.MOVIES), 1, count - 1); 62 assertInRange(GenreItems.getId(Genres.COMEDY), 1, count - 1); 63 assertInRange(GenreItems.getId(Genres.TRAVEL), 1, count - 1); 64 assertInRange(GenreItems.getId(Genres.DRAMA), 1, count - 1); 65 assertInRange(GenreItems.getId(Genres.EDUCATION), 1, count - 1); 66 assertInRange(GenreItems.getId(Genres.ANIMAL_WILDLIFE), 1, count - 1); 67 assertInRange(GenreItems.getId(Genres.NEWS), 1, count - 1); 68 assertInRange(GenreItems.getId(Genres.GAMING), 1, count - 1); 69 } 70 71 @Test 72 public void testGetId_lmp_mr1() { 73 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) { 74 assertEquals(GenreItems.ID_ALL_CHANNELS, GenreItems.getId(Genres.ARTS)); 75 assertEquals(GenreItems.ID_ALL_CHANNELS, GenreItems.getId(Genres.ENTERTAINMENT)); 76 assertEquals(GenreItems.ID_ALL_CHANNELS, GenreItems.getId(Genres.LIFE_STYLE)); 77 assertEquals(GenreItems.ID_ALL_CHANNELS, GenreItems.getId(Genres.MUSIC)); 78 assertEquals(GenreItems.ID_ALL_CHANNELS, GenreItems.getId(Genres.PREMIER)); 79 assertEquals(GenreItems.ID_ALL_CHANNELS, GenreItems.getId(Genres.TECH_SCIENCE)); 80 } else { 81 int count = GenreItems.getGenreCount(); 82 assertInRange(GenreItems.getId(Genres.ARTS), 1, count - 1); 83 assertInRange(GenreItems.getId(Genres.ENTERTAINMENT), 1, count - 1); 84 assertInRange(GenreItems.getId(Genres.LIFE_STYLE), 1, count - 1); 85 assertInRange(GenreItems.getId(Genres.MUSIC), 1, count - 1); 86 assertInRange(GenreItems.getId(Genres.PREMIER), 1, count - 1); 87 assertInRange(GenreItems.getId(Genres.TECH_SCIENCE), 1, count - 1); 88 } 89 } 90 91 private void assertInRange(int value, int lower, int upper) { 92 assertTrue(value >= lower && value <= upper); 93 } 94 } 95