1 /* 2 * Copyright (C) 2011 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.nativescanner; 18 19 import java.io.BufferedReader; 20 import java.io.IOException; 21 import java.io.InputStreamReader; 22 import java.util.ArrayList; 23 import java.util.List; 24 25 /** 26 * Read from the BufferedReader a list of test case names and test cases. 27 * 28 * The expected format of the incoming test list: 29 * TEST_CASE_NAME. 30 * TEST_NAME1 31 * TEST_NAME2 32 * 33 * The output: 34 * suite:TestSuite 35 * case:TEST_CASE_NAME 36 * test:TEST_NAME1 37 * test:TEST_NAME2 38 */ 39 class TestScanner { 40 41 private final String mTestSuite; 42 43 private final BufferedReader mReader; 44 TestScanner(BufferedReader reader, String testSuite)45 TestScanner(BufferedReader reader, String testSuite) { 46 mTestSuite = testSuite; 47 mReader = reader; 48 } 49 getTestNames()50 public List<String> getTestNames() throws IOException { 51 List<String> testNames = new ArrayList<String>(); 52 53 String testCaseName = null; 54 String line; 55 while ((line = mReader.readLine()) != null) { 56 if (line.length() > 0) { 57 if (line.charAt(0) == ' ') { 58 if (testCaseName != null) { 59 testNames.add("test:" + line.trim()); 60 } else { 61 throw new IOException("TEST_CASE_NAME not defined before first test."); 62 } 63 } else { 64 testCaseName = line.trim(); 65 if (testCaseName.endsWith(".")) { 66 testCaseName = testCaseName.substring(0, testCaseName.length()-1); 67 } 68 testNames.add("suite:" + mTestSuite); 69 testNames.add("case:" + testCaseName); 70 } 71 } 72 } 73 return testNames; 74 } 75 } 76