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