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