Home | History | Annotate | Download | only in widget
      1 /*
      2  * Copyright (C) 2017 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.widget;
     18 
     19 import android.content.Context;
     20 import android.perftests.utils.BenchmarkState;
     21 import android.perftests.utils.PerfStatusReporter;
     22 import android.support.test.InstrumentationRegistry;
     23 import android.support.test.filters.LargeTest;
     24 import android.support.test.runner.AndroidJUnit4;
     25 import android.view.LayoutInflater;
     26 
     27 import com.android.perftests.core.R;
     28 
     29 import java.util.Collection;
     30 import java.util.Arrays;
     31 
     32 import org.junit.Test;
     33 import org.junit.Rule;
     34 import org.junit.runners.Parameterized;
     35 import org.junit.runners.Parameterized.Parameters;
     36 import org.junit.runner.RunWith;
     37 
     38 import static org.junit.Assert.assertTrue;
     39 
     40 @LargeTest
     41 @RunWith(Parameterized.class)
     42 public class TextViewFontFamilyLayoutPerfTest {
     43     @Parameters(name = "{0}")
     44     public static Collection layouts() {
     45         return Arrays.asList(new Object[][] {
     46                 { "String fontFamily attribute", R.layout.test_textview_font_family_string},
     47                 { "File fontFamily attribute", R.layout.test_textview_font_family_file},
     48                 { "XML fontFamily attribute", R.layout.test_textview_font_family_xml},
     49         });
     50     }
     51 
     52     private int mLayoutId;
     53 
     54     public TextViewFontFamilyLayoutPerfTest(String key, int layoutId) {
     55         mLayoutId = layoutId;
     56     }
     57 
     58     @Rule
     59     public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
     60 
     61     @Test
     62     public void testConstruction() throws Throwable {
     63         final Context context = InstrumentationRegistry.getTargetContext();
     64         final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
     65         final LayoutInflater inflator =
     66                 (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     67 
     68         while (state.keepRunning()) {
     69             inflator.inflate(mLayoutId, null, false);
     70         }
     71     }
     72 }
     73