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