blob: 1d34f938381811ebfb2402c3c1b79647b0566069 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.content.res.ColorStateList;
sergeyvaad8ae32017-02-28 18:28:27 -080020import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.test.AndroidTestCase;
Tadashi G. Takaokab4470f22019-01-15 18:29:15 +090022
23import androidx.test.filters.SmallTest;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
sergeyvaad8ae32017-02-28 18:28:27 -080025import com.android.frameworks.coretests.R;
26
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027/**
28 * Tests of {@link android.graphics.ColorStateList}
29 */
30
31public class ColorStateListTest extends AndroidTestCase {
32
33 private Resources mResources;
34 private int mFailureColor;
35
36 @Override
37 protected void setUp() throws Exception {
38 super.setUp();
39 mResources = mContext.getResources();
40 mFailureColor = mResources.getColor(R.color.failColor);
41 }
42
43 @SmallTest
44 public void testStateIsInList() throws Exception {
45 ColorStateList colorStateList = mResources.getColorStateList(R.color.color1);
46 int[] focusedState = {android.R.attr.state_focused};
47 int focusColor = colorStateList.getColorForState(focusedState, R.color.failColor);
48 assertEquals(mResources.getColor(R.color.testcolor1), focusColor);
49 }
50
51 @SmallTest
52 public void testEmptyState() throws Exception {
53 ColorStateList colorStateList = mResources.getColorStateList(R.color.color1);
54 int[] emptyState = {};
55 int defaultColor = colorStateList.getColorForState(emptyState, mFailureColor);
56 assertEquals(mResources.getColor(R.color.testcolor2), defaultColor);
57 }
58
59 @SmallTest
60 public void testGetColor() throws Exception {
61 int defaultColor = mResources.getColor(R.color.color1);
62 assertEquals(mResources.getColor(R.color.testcolor2), defaultColor);
63 }
64
65 @SmallTest
66 public void testGetColorWhenListHasNoDefault() throws Exception {
67 int defaultColor = mResources.getColor(R.color.color_no_default);
68 assertEquals(mResources.getColor(R.color.testcolor1), defaultColor);
69 }
70}