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.view;
18
19import com.android.frameworks.coretests.R;
20import android.test.suitebuilder.annotation.MediumTest;
21
22import android.test.ActivityInstrumentationTestCase2;
23import android.widget.Button;
24
25/**
26 * Exercises {@link android.view.View}'s tags property.
27 */
28public class SetTagsTest extends ActivityInstrumentationTestCase2<Disabled> {
29    private Button mView;
30
31    public SetTagsTest() {
32        super("com.android.frameworks.coretests", Disabled.class);
33    }
34
35    @Override
36    public void setUp() throws Exception {
37        super.setUp();
38
39        mView = (Button) getActivity().findViewById(R.id.disabledButton);
40    }
41
42    @MediumTest
43    public void testSetUpConditions() throws Exception {
44        assertNotNull(mView);
45    }
46
47    @MediumTest
48    public void testSetTag() throws Exception {
49        mView.setTag("1");
50    }
51
52    @MediumTest
53    public void testGetTag() throws Exception {
54        Object o = new Object();
55        mView.setTag(o);
56
57        final Object stored = mView.getTag();
58        assertNotNull(stored);
59        assertSame("The stored tag is inccorect", o, stored);
60    }
61
62    @MediumTest
63    public void testSetTagWithKey() throws Exception {
64        mView.setTag(R.id.a, "2");
65    }
66
67    @MediumTest
68    public void testGetTagWithKey() throws Exception {
69        Object o = new Object();
70        mView.setTag(R.id.a, o);
71
72        final Object stored = mView.getTag(R.id.a);
73        assertNotNull(stored);
74        assertSame("The stored tag is inccorect", o, stored);
75    }
76
77    @MediumTest
78    public void testSetTagWithFrameworkId() throws Exception {
79        boolean result = false;
80        try {
81            mView.setTag(android.R.id.list, "2");
82        } catch (IllegalArgumentException e) {
83            result = true;
84        }
85        assertTrue("Setting a tag with a framework id did not throw an exception", result);
86    }
87
88    @MediumTest
89    public void testSetTagWithNoPackageId() throws Exception {
90        boolean result = false;
91        try {
92            mView.setTag(0x000000AA, "2");
93        } catch (IllegalArgumentException e) {
94            result = true;
95        }
96        assertTrue("Setting a tag with an id with no package did not throw an exception", result);
97    }
98
99    @MediumTest
100    public void testSetTagInternalWithFrameworkId() throws Exception {
101        mView.setTagInternal(android.R.id.list, "2");
102    }
103
104    @MediumTest
105    public void testSetTagInternalWithApplicationId() throws Exception {
106        boolean result = false;
107        try {
108            mView.setTagInternal(R.id.a, "2");
109        } catch (IllegalArgumentException e) {
110            result = true;
111        }
112        assertTrue("Setting a tag with an id with app package did not throw an exception", result);
113    }
114}
115