aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/src/com/android/tv/data/GenreItemTest.java
blob: fb48fd4131b96595458616c192e79002319dc28b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.tv.data;

import android.media.tv.TvContract.Programs.Genres;
import android.os.Build;
import android.support.test.filters.SmallTest;
import android.test.AndroidTestCase;

/**
 * Tests for {@link Channel}.
 */
@SmallTest
public class GenreItemTest extends AndroidTestCase {
    private static final String INVALID_GENRE = "INVALID GENRE";

    public void testGetLabels() {
        // Checks if no exception is thrown.
        GenreItems.getLabels(getContext());
    }

    public void testGetCanonicalGenre() {
        int count = GenreItems.getGenreCount();
        assertNull(GenreItems.getCanonicalGenre(GenreItems.ID_ALL_CHANNELS));
        for (int i = 1; i < count; ++i) {
            assertNotNull(GenreItems.getCanonicalGenre(i));
        }
    }

    public void testGetId_base() {
        int count = GenreItems.getGenreCount();
        assertEquals(GenreItems.ID_ALL_CHANNELS, GenreItems.getId(null));
        assertEquals(GenreItems.ID_ALL_CHANNELS, GenreItems.getId(INVALID_GENRE));
        assertInRange(GenreItems.getId(Genres.FAMILY_KIDS), 1, count - 1);
        assertInRange(GenreItems.getId(Genres.SPORTS), 1, count - 1);
        assertInRange(GenreItems.getId(Genres.SHOPPING), 1, count - 1);
        assertInRange(GenreItems.getId(Genres.MOVIES), 1, count - 1);
        assertInRange(GenreItems.getId(Genres.COMEDY), 1, count - 1);
        assertInRange(GenreItems.getId(Genres.TRAVEL), 1, count - 1);
        assertInRange(GenreItems.getId(Genres.DRAMA), 1, count - 1);
        assertInRange(GenreItems.getId(Genres.EDUCATION), 1, count - 1);
        assertInRange(GenreItems.getId(Genres.ANIMAL_WILDLIFE), 1, count - 1);
        assertInRange(GenreItems.getId(Genres.NEWS), 1, count - 1);
        assertInRange(GenreItems.getId(Genres.GAMING), 1, count - 1);
    }

    public void testGetId_lmp_mr1() {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
            assertEquals(GenreItems.ID_ALL_CHANNELS, GenreItems.getId(Genres.ARTS));
            assertEquals(GenreItems.ID_ALL_CHANNELS, GenreItems.getId(Genres.ENTERTAINMENT));
            assertEquals(GenreItems.ID_ALL_CHANNELS, GenreItems.getId(Genres.LIFE_STYLE));
            assertEquals(GenreItems.ID_ALL_CHANNELS, GenreItems.getId(Genres.MUSIC));
            assertEquals(GenreItems.ID_ALL_CHANNELS, GenreItems.getId(Genres.PREMIER));
            assertEquals(GenreItems.ID_ALL_CHANNELS, GenreItems.getId(Genres.TECH_SCIENCE));
        } else {
            int count = GenreItems.getGenreCount();
            assertInRange(GenreItems.getId(Genres.ARTS), 1, count - 1);
            assertInRange(GenreItems.getId(Genres.ENTERTAINMENT), 1, count - 1);
            assertInRange(GenreItems.getId(Genres.LIFE_STYLE), 1, count - 1);
            assertInRange(GenreItems.getId(Genres.MUSIC), 1, count - 1);
            assertInRange(GenreItems.getId(Genres.PREMIER), 1, count - 1);
            assertInRange(GenreItems.getId(Genres.TECH_SCIENCE), 1, count - 1);
        }
    }

    private void assertInRange(int value, int lower, int upper) {
        assertTrue(value >= lower && value <= upper);
    }
}