1 /*
2  * Copyright (C) 2006 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.view;
18 
19 import android.content.Context;
20 import android.content.res.Resources;
21 import android.test.AndroidTestCase;
22 import android.test.PerformanceTestCase;
23 import android.util.AttributeSet;
24 
25 import androidx.test.filters.SmallTest;
26 
27 import com.android.frameworks.coretests.R;
28 
29 public class InflateTest extends AndroidTestCase implements PerformanceTestCase {
30     private LayoutInflater mInflater;
31     private Resources mResources;
32     private View mView;
33 
34     @Override
setUp()35     protected void setUp() throws Exception {
36         super.setUp();
37 
38         mInflater = LayoutInflater.from(mContext);
39         mResources = mContext.getResources();
40 
41         // to try to make things consistent, before doing timing
42         // do an initial instantiation of the layout and then clear
43         // out the layout cache.
44 //            mInflater.inflate(mResId, null, null);
45 //            mResources.flushLayoutCache();
46     }
47 
startPerformance(PerformanceTestCase.Intermediates intermediates)48     public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
49         return 0;
50     }
51 
isPerformanceOnly()52     public boolean isPerformanceOnly() {
53         return false;
54     }
55 
inflateTest(int resourceId)56     public void inflateTest(int resourceId) {
57         mView = mInflater.inflate(resourceId, null);
58         mResources.flushLayoutCache();
59     }
60 
inflateCachedTest(int resourceId)61     public void inflateCachedTest(int resourceId) {
62         // Make sure this layout is in the cache.
63         mInflater.inflate(resourceId, null);
64 
65         mInflater.inflate(resourceId, null);
66     }
67 
68     @SmallTest
testLayout1()69     public void testLayout1() throws Exception {
70         inflateTest(R.layout.layout_one);
71     }
72 
73     @SmallTest
testLayout2()74     public void testLayout2() throws Exception {
75         inflateTest(R.layout.layout_two);
76     }
77 
78     @SmallTest
testLayout3()79     public void testLayout3() throws Exception {
80         inflateTest(R.layout.layout_three);
81     }
82 
83     @SmallTest
testLayout4()84     public void testLayout4() throws Exception {
85         inflateTest(R.layout.layout_four);
86     }
87 
88     @SmallTest
testLayout5()89     public void testLayout5() throws Exception {
90         inflateTest(R.layout.layout_five);
91     }
92 
93     @SmallTest
testLayout6()94     public void testLayout6() throws Exception {
95         inflateTest(R.layout.layout_six);
96     }
97 
98     @SmallTest
testCachedLayout1()99     public void testCachedLayout1() throws Exception {
100         inflateCachedTest(R.layout.layout_one);
101     }
102 
103     @SmallTest
testCachedLayout2()104     public void testCachedLayout2() throws Exception {
105         inflateCachedTest(R.layout.layout_two);
106     }
107 
108     @SmallTest
testCachedLayout3()109     public void testCachedLayout3() throws Exception {
110         inflateCachedTest(R.layout.layout_three);
111     }
112 
113     @SmallTest
testCachedLayout4()114     public void testCachedLayout4() throws Exception {
115         inflateCachedTest(R.layout.layout_four);
116     }
117 
118     @SmallTest
testCachedLayout5()119     public void testCachedLayout5() throws Exception {
120         inflateCachedTest(R.layout.layout_five);
121     }
122 
123     @SmallTest
testCachedLayout6()124     public void testCachedLayout6() throws Exception {
125         inflateCachedTest(R.layout.layout_six);
126     }
127 
128 //    public void testLayoutTag() throws Exception {
129 //        public void setUp
130 //        (Context
131 //        context){
132 //        setUp(context, R.layout.layout_tag);
133 //    }
134 //        public void run
135 //        ()
136 //        {
137 //            super.run();
138 //            if (!"MyTag".equals(mView.getTag())) {
139 //                throw new RuntimeException("Incorrect tag: " + mView.getTag());
140 //            }
141 //        }
142 //    }
143 
144     public static class ViewOne extends View {
ViewOne(Context context)145         public ViewOne(Context context) {
146             super(context);
147         }
148 
ViewOne(Context context, AttributeSet attrs)149         public ViewOne(Context context, AttributeSet attrs) {
150             super(context, attrs);
151         }
152     }
153 }
154