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.drawable;
18
19import android.R;
20import android.graphics.Canvas;
21import android.graphics.ColorFilter;
22import android.util.StateSet;
23import android.view.MockView;
24
25import junit.framework.TestCase;
26
27/**
28 * Tests for StateListDrawable
29 *
30 */
31
32public class StateListDrawableTest extends TestCase {
33
34    private StateListDrawable slDrawable;
35    private MockDrawable mockFocusedDrawable;
36    private MockDrawable mockCheckedDrawable;
37    private MockView mockView;
38    private MockDrawable mockDefaultDrawable;
39
40
41    // Re-enable tests when we are running in the framework-test directory which allows
42    // access to package private access for MockView
43
44    public void broken_testFocusScenarioSetStringWildcardFirst() throws Exception {
45        int focusedStateSet[] = {R.attr.state_focused};
46        int checkedStateSet[] = {R.attr.state_checked};
47        slDrawable.addState(StateSet.WILD_CARD,
48                               mockDefaultDrawable);
49        slDrawable.addState(checkedStateSet, mockCheckedDrawable);
50        slDrawable.addState(focusedStateSet, mockFocusedDrawable);
51        mockView.requestFocus();
52        mockView.getBackground().draw(null);
53        assertTrue(mockDefaultDrawable.wasDrawn);
54    }
55
56    public void broken_testFocusScenarioStateSetWildcardLast() throws Exception {
57        int focusedStateSet[] = {R.attr.state_focused};
58        int checkedStateSet[] = {R.attr.state_checked};
59        slDrawable.addState(checkedStateSet, mockCheckedDrawable);
60        slDrawable.addState(focusedStateSet, mockFocusedDrawable);
61        slDrawable.addState(StateSet.WILD_CARD,
62                               mockDefaultDrawable);
63        mockView.requestFocus();
64        mockView.getBackground().draw(null);
65        assertTrue(mockFocusedDrawable.wasDrawn);
66    }
67
68
69    protected void setUp() throws Exception {
70        super.setUp();
71        slDrawable = new StateListDrawable();
72        mockFocusedDrawable = new MockDrawable();
73        mockCheckedDrawable = new MockDrawable();
74        mockDefaultDrawable = new MockDrawable();
75        mockView = new MockView();
76        mockView.setBackgroundDrawable(slDrawable);
77    }
78
79    static class MockDrawable extends Drawable {
80
81        public boolean wasDrawn = false;
82
83        public void draw(Canvas canvas) {
84            wasDrawn = true;
85        }
86
87        public void setAlpha(int alpha) {
88        }
89
90        public void setColorFilter(ColorFilter cf) {
91        }
92
93        public int getOpacity() {
94            return android.graphics.PixelFormat.UNKNOWN;
95        }
96    }
97
98}
99