The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 17 | package android.graphics; |
| 18 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import android.content.res.ColorStateList; |
sergeyv | aad8ae3 | 2017-02-28 18:28:27 -0800 | [diff] [blame] | 20 | import android.content.res.Resources; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.test.AndroidTestCase; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame^] | 22 | |
| 23 | import androidx.test.filters.SmallTest; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
sergeyv | aad8ae3 | 2017-02-28 18:28:27 -0800 | [diff] [blame] | 25 | import com.android.frameworks.coretests.R; |
| 26 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | /** |
| 28 | * Tests of {@link android.graphics.ColorStateList} |
| 29 | */ |
| 30 | |
| 31 | public 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 | } |