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