| 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; | 
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.test.suitebuilder.annotation.SmallTest; | 
|  | 23 |  | 
| sergeyv | aad8ae3 | 2017-02-28 18:28:27 -0800 | [diff] [blame^] | 24 | import com.android.frameworks.coretests.R; | 
|  | 25 |  | 
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | /** | 
|  | 27 | * Tests of {@link android.graphics.ColorStateList} | 
|  | 28 | */ | 
|  | 29 |  | 
|  | 30 | public 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 | } |