1/*
2 * Copyright (C) 2007 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
17package android.graphics;
18
19import com.android.frameworks.graphicstests.R;
20
21import android.content.res.Resources;
22import android.content.res.ColorStateList;
23import android.test.AndroidTestCase;
24import android.test.suitebuilder.annotation.SmallTest;
25
26/**
27 * Tests of {@link android.graphics.ColorStateList}
28 */
29
30public class ColorStateListTest extends AndroidTestCase {
31
32    private Resources mResources;
33    private int mFailureColor;
34
35    @Override
36    protected void setUp() throws Exception {
37        super.setUp();
38        mResources = mContext.getResources();
39        mFailureColor = mResources.getColor(R.color.failColor);
40    }
41
42    @SmallTest
43    public void testStateIsInList() throws Exception {
44        ColorStateList colorStateList = mResources.getColorStateList(R.color.color1);
45        int[] focusedState = {android.R.attr.state_focused};
46        int focusColor = colorStateList.getColorForState(focusedState, R.color.failColor);
47        assertEquals(mResources.getColor(R.color.testcolor1), focusColor);
48    }
49
50    @SmallTest
51    public void testEmptyState() throws Exception {
52        ColorStateList colorStateList = mResources.getColorStateList(R.color.color1);
53        int[] emptyState = {};
54        int defaultColor = colorStateList.getColorForState(emptyState, mFailureColor);
55        assertEquals(mResources.getColor(R.color.testcolor2), defaultColor);
56    }
57
58    @SmallTest
59    public void testGetColor() throws Exception {
60        int defaultColor = mResources.getColor(R.color.color1);
61        assertEquals(mResources.getColor(R.color.testcolor2), defaultColor);
62    }
63
64    @SmallTest
65    public void testGetColorWhenListHasNoDefault() throws Exception {
66        int defaultColor = mResources.getColor(R.color.color_no_default);
67        assertEquals(mResources.getColor(R.color.testcolor1), defaultColor);
68    }
69}
70