1 /* 2 * Copyright (C) 2012 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.cts.uiautomator; 18 19 import android.os.Bundle; 20 import android.support.v4.app.Fragment; 21 import android.util.Log; 22 23 import java.util.ArrayList; 24 import java.util.HashMap; 25 import java.util.List; 26 import java.util.Map; 27 28 public class TestItems { 29 private static String LOG_TAG = TestItems.class.getSimpleName(); 30 private static List<TestItem> ITEMS = new ArrayList<TestItem>(); 31 private static Map<String, TestItem> ITEM_MAP = new HashMap<String, TestItem>(); 32 33 public static class TestItem { 34 public String mId; 35 public String mName; 36 private final Class<Fragment> mClassFragment; 37 public String mTestDescription; 38 39 @SuppressWarnings("unchecked") 40 public TestItem(String id, String name, Class<?> clsf) { 41 mId = id; 42 mName = name; 43 mClassFragment = (Class<Fragment>) clsf; 44 } 45 46 @Override 47 public String toString() { 48 return mName; 49 } 50 } 51 52 static { 53 addTestItem(new TestItem("1", "Test 1", Test1DetailFragment.class)); 54 addTestItem(new TestItem("2", "Test 2", Test2DetailFragment.class)); 55 addTestItem(new TestItem("3", "Test 3", Test3DetailFragment.class)); 56 addTestItem(new TestItem("4", "Test 4", Test4DetailFragment.class)); 57 addTestItem(new TestItem("5", "Test 5", Test5DetailFragment.class)); 58 addTestItem(new TestItem("6", "Test 6", Test6DetailFragment.class)); 59 addTestItem(new TestItem("7", "Test 7", TestGenericDetailFragment.class)); 60 addTestItem(new TestItem("8", "Test 8", TestGenericDetailFragment.class)); 61 addTestItem(new TestItem("9", "Test 9", TestGenericDetailFragment.class)); 62 addTestItem(new TestItem("10", "Test 10", TestGenericDetailFragment.class)); 63 addTestItem(new TestItem("11", "Test 11", TestGenericDetailFragment.class)); 64 addTestItem(new TestItem("12", "Test 12", TestGenericDetailFragment.class)); 65 addTestItem(new TestItem("13", "Test 13", TestGenericDetailFragment.class)); 66 addTestItem(new TestItem("14", "Test 14", TestGenericDetailFragment.class)); 67 addTestItem(new TestItem("15", "Test 15", TestGenericDetailFragment.class)); 68 addTestItem(new TestItem("16", "Test 16", TestGenericDetailFragment.class)); 69 addTestItem(new TestItem("17", "Test 17", TestGenericDetailFragment.class)); 70 addTestItem(new TestItem("18", "Test 18", TestGenericDetailFragment.class)); 71 addTestItem(new TestItem("19", "Test 19", TestGenericDetailFragment.class)); 72 addTestItem(new TestItem("20", "Test 20", TestGenericDetailFragment.class)); 73 addTestItem(new TestItem("21", "Test 21", TestGenericDetailFragment.class)); 74 addTestItem(new TestItem("22", "Test 22", TestGenericDetailFragment.class)); 75 addTestItem(new TestItem("23", "Test 23", TestGenericDetailFragment.class)); 76 addTestItem(new TestItem("24", "Test 24", TestGenericDetailFragment.class)); 77 addTestItem(new TestItem("25", "Test 25", TestGenericDetailFragment.class)); 78 addTestItem(new TestItem("26", "Test 26", TestGenericDetailFragment.class)); 79 addTestItem(new TestItem("27", "Test 27", TestGenericDetailFragment.class)); 80 addTestItem(new TestItem("28", "Test 28", TestGenericDetailFragment.class)); 81 addTestItem(new TestItem("29", "Test 29", TestGenericDetailFragment.class)); 82 addTestItem(new TestItem("30", "Test 30", TestGenericDetailFragment.class)); 83 addTestItem(new TestItem("31", "Test 31", TestGenericDetailFragment.class)); 84 addTestItem(new TestItem("32", "Test 32", TestGenericDetailFragment.class)); 85 addTestItem(new TestItem("33", "Test 33", TestGenericDetailFragment.class)); 86 addTestItem(new TestItem("34", "Test 34", TestGenericDetailFragment.class)); 87 addTestItem(new TestItem("35", "Test 35", TestGenericDetailFragment.class)); 88 addTestItem(new TestItem("36", "Test 36", TestGenericDetailFragment.class)); 89 addTestItem(new TestItem("37", "Test 37", TestGenericDetailFragment.class)); 90 addTestItem(new TestItem("38", "Test 38", TestGenericDetailFragment.class)); 91 addTestItem(new TestItem("39", "Test 39", TestGenericDetailFragment.class)); 92 addTestItem(new TestItem("40", "Test 40", TestGenericDetailFragment.class)); 93 } 94 95 private static void addTestItem(TestItem item) { 96 ITEMS.add(item); 97 ITEM_MAP.put(item.mId, item); 98 } 99 100 public static List<TestItem> getTests() { 101 return ITEMS; 102 } 103 104 public static TestItem getTest(String id) { 105 return ITEM_MAP.get(id); 106 } 107 108 public static TestItem getTest(int pos) { 109 return ITEMS.get(pos); 110 } 111 112 public static Fragment getFragment(String id) { 113 try { 114 Fragment fragment = getTest(id).mClassFragment.newInstance(); 115 Bundle arguments = new Bundle(); 116 arguments.putString("item_id", id); 117 fragment.setArguments(arguments); 118 return fragment; 119 } catch (InstantiationException e) { 120 Log.e(LOG_TAG, "Exception", e); 121 return null; 122 } catch (IllegalAccessException e) { 123 Log.e(LOG_TAG, "Exception", e); 124 return null; 125 } 126 } 127 } 128