summaryrefslogtreecommitdiffstats
path: root/tests/AndroidTests/src/com/android/unit_tests/InflateTest.java
blob: d7c9d60d0935d96fdb20e3f4ea06c37fc810588c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.unit_tests;

import android.content.Context;
import android.content.res.Resources;
import android.test.AndroidTestCase;
import android.test.PerformanceTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import java.util.Map;

public class InflateTest extends AndroidTestCase implements PerformanceTestCase {
    private LayoutInflater mInflater;
    private Resources mResources;
    private View mView;

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        mInflater = LayoutInflater.from(mContext);
        mResources = mContext.getResources();

        // to try to make things consistent, before doing timing
        // do an initial instantiation of the layout and then clear
        // out the layout cache.
//            mInflater.inflate(mResId, null, null);
//            mResources.flushLayoutCache();
    }

    public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
        return 0;
    }

    public boolean isPerformanceOnly() {
        return false;
    }

    public void inflateTest(int resourceId) {
        mView = mInflater.inflate(resourceId, null);
        mResources.flushLayoutCache();
    }

    public void inflateCachedTest(int resourceId) {
        // Make sure this layout is in the cache.
        mInflater.inflate(resourceId, null);

        mInflater.inflate(resourceId, null);
    }

    @SmallTest
    public void testLayout1() throws Exception {
        inflateTest(R.layout.layout_one);
    }

    @SmallTest
    public void testLayout2() throws Exception {
        inflateTest(R.layout.layout_two);
    }

    @SmallTest
    public void testLayout3() throws Exception {
        inflateTest(R.layout.layout_three);
    }

    @SmallTest
    public void testLayout4() throws Exception {
        inflateTest(R.layout.layout_four);
    }

    @SmallTest
    public void testLayout5() throws Exception {
        inflateTest(R.layout.layout_five);
    }

    @SmallTest
    public void testLayout6() throws Exception {
        inflateTest(R.layout.layout_six);
    }

    @SmallTest
    public void testCachedLayout1() throws Exception {
        inflateCachedTest(R.layout.layout_one);
    }

    @SmallTest
    public void testCachedLayout2() throws Exception {
        inflateCachedTest(R.layout.layout_two);
    }

    @SmallTest
    public void testCachedLayout3() throws Exception {
        inflateCachedTest(R.layout.layout_three);
    }

    @SmallTest
    public void testCachedLayout4() throws Exception {
        inflateCachedTest(R.layout.layout_four);
    }

    @SmallTest
    public void testCachedLayout5() throws Exception {
        inflateCachedTest(R.layout.layout_five);
    }

    @SmallTest
    public void testCachedLayout6() throws Exception {
        inflateCachedTest(R.layout.layout_six);
    }

//    public void testLayoutTag() throws Exception {
//        public void setUp
//        (Context
//        context){
//        setUp(context, R.layout.layout_tag);
//    }
//        public void run
//        ()
//        {
//            super.run();
//            if (!"MyTag".equals(mView.getTag())) {
//                throw new RuntimeException("Incorrect tag: " + mView.getTag());
//            }
//        }
//    }

    public static class ViewOne extends View {
        public ViewOne(Context context) {
            super(context);
        }

        public ViewOne(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    }
}