1/*
2 * Copyright (C) 2016 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
17package android.widget;
18
19import android.app.Activity;
20import android.os.Bundle;
21import android.perftests.utils.PerfStatusReporter;
22import android.util.Log;
23
24import android.perftests.utils.BenchmarkState;
25import android.perftests.utils.StubActivity;
26import android.support.test.filters.LargeTest;
27import android.support.test.runner.AndroidJUnit4;
28import android.support.test.rule.ActivityTestRule;
29import android.support.test.InstrumentationRegistry;
30
31import java.util.Locale;
32import java.util.Collection;
33import java.util.Arrays;
34
35import org.junit.Test;
36import org.junit.Rule;
37import org.junit.runners.Parameterized;
38import org.junit.runners.Parameterized.Parameters;
39import org.junit.runner.RunWith;
40
41@LargeTest
42@RunWith(Parameterized.class)
43public class TextViewSetTextLocalePerfTest {
44    @Parameters(name = "{0}")
45    public static Collection locales() {
46        return Arrays.asList(new Object[][] {
47            { "SameLocale", "en-US", "en-US" },
48            { "DifferentLocale", "en-US", "ja-JP"}
49        });
50    }
51
52    private String mMetricKey;
53    private Locale mFirstLocale;
54    private Locale mSecondLocale;
55
56    public TextViewSetTextLocalePerfTest(
57            String metricKey, String firstLocale, String secondLocale) {
58        mMetricKey = metricKey;
59        mFirstLocale = Locale.forLanguageTag(firstLocale);
60        mSecondLocale = Locale.forLanguageTag(secondLocale);
61    }
62
63    @Rule
64    public ActivityTestRule<StubActivity> mActivityRule = new ActivityTestRule(StubActivity.class);
65
66    @Rule
67    public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
68
69    @Test
70    public void testSetTextLocale() {
71        TextView textView = new TextView(mActivityRule.getActivity());
72
73        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
74
75        while (state.keepRunning()) {
76            textView.setTextLocale(mFirstLocale);
77            textView.setTextLocale(mSecondLocale);
78        }
79    }
80}
81