1 /* 2 * Copyright (C) 2015 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 package com.android.compatibility.common.deviceinfo; 17 18 import android.os.Bundle; 19 20 import java.lang.StringBuilder; 21 import java.util.ArrayList; 22 import java.util.HashSet; 23 import java.util.List; 24 25 import com.android.compatibility.common.util.DeviceInfoStore; 26 27 /** 28 * Collector for testing DeviceInfo 29 */ 30 public class TestDeviceInfo extends DeviceInfo { 31 32 @Override setUp()33 protected void setUp() throws Exception { 34 mActivityList = new HashSet<String>(); 35 mActivityList.add(getClass().getName()); 36 } 37 38 @Override collectDeviceInfo(DeviceInfoStore store)39 protected void collectDeviceInfo(DeviceInfoStore store) throws Exception { 40 41 // Test primitive results 42 store.addResult("test_boolean", true); 43 store.addResult("test_double", 1.23456789); 44 store.addResult("test_int", 123456789); 45 store.addResult("test_long", Long.MAX_VALUE); 46 store.addResult("test_string", "test string"); 47 List<String> list = new ArrayList<>(); 48 list.add("test string 1"); 49 list.add("test string 2"); 50 list.add("test string 3"); 51 store.addListResult("test_strings", list); 52 53 // Test group 54 store.startGroup("test_group"); 55 store.addResult("test_boolean", false); 56 store.addResult("test_double", 9.87654321); 57 store.addResult("test_int", 987654321); 58 store.addResult("test_long", Long.MAX_VALUE); 59 store.addResult("test_string", "test group string"); 60 list = new ArrayList<>(); 61 list.add("test group string 1"); 62 list.add("test group string 2"); 63 list.add("test group string 3"); 64 store.addListResult("test_strings", list); 65 store.endGroup(); // test_group 66 67 // Test array of groups 68 store.startArray("test_groups"); 69 for (int i = 1; i < 4; i++) { 70 store.startGroup(); 71 store.addResult("test_string", "test groups string " + i); 72 list = new ArrayList<>(); 73 list.add("test groups string " + i + "-1"); 74 list.add("test groups string " + i + "-2"); 75 list.add("test groups string " + i + "-3"); 76 store.addListResult("test_strings", list); 77 store.endGroup(); 78 } 79 store.endArray(); // test_groups 80 81 // Test max 82 StringBuilder sb = new StringBuilder(); 83 int[] arr = new int[1001]; 84 for (int i = 0; i < 1001; i++) { 85 sb.append("a"); 86 arr[i] = i; 87 } 88 store.addResult("max_length_string", sb.toString()); 89 store.addArrayResult("max_num_ints", arr); 90 } 91 } 92