Home | History | Annotate | Download | only in testtype
      1 /*
      2  * Copyright (C) 2010 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.tradefed.testtype;
     17 
     18 import com.android.tradefed.log.LogUtil.CLog;
     19 
     20 import junit.framework.TestCase;
     21 
     22 import java.io.BufferedReader;
     23 import java.io.File;
     24 import java.io.IOException;
     25 import java.io.InputStream;
     26 import java.io.InputStreamReader;
     27 import java.util.Vector;
     28 
     29 
     30 /**
     31  * Base test class for various GTest parsers
     32  */
     33 public abstract class GTestParserTestBase extends TestCase {
     34     protected static final String TEST_TYPE_DIR = "testtype";
     35     protected static final String TEST_MODULE_NAME = "module";
     36     protected static final String GTEST_OUTPUT_FILE_1 = "gtest_output1.txt";
     37     protected static final String GTEST_OUTPUT_FILE_2 = "gtest_output2.txt";
     38     protected static final String GTEST_OUTPUT_FILE_3 = "gtest_output3.txt";
     39     protected static final String GTEST_OUTPUT_FILE_4 = "gtest_output4.txt";
     40     protected static final String GTEST_OUTPUT_FILE_5 = "gtest_output5.txt";
     41     protected static final String GTEST_OUTPUT_FILE_6 = "gtest_output6.txt";
     42     protected static final String GTEST_OUTPUT_FILE_7 = "gtest_output7.txt";
     43     protected static final String GTEST_OUTPUT_FILE_8 = "gtest_output8.txt";
     44     protected static final String GTEST_LIST_FILE_1 = "gtest_list1.txt";
     45     protected static final String GTEST_LIST_FILE_2 = "gtest_list2.txt";
     46     protected static final String GTEST_LIST_FILE_3 = "gtest_list3.txt";
     47 
     48     /**
     49      * Helper to read a file from the res/testtype directory and return its contents as a String[]
     50      *
     51      * @param filename the name of the file (without the extension) in the res/testtype directory
     52      * @return a String[] of the
     53      */
     54     protected String[] readInFile(String filename) {
     55         Vector<String> fileContents = new Vector<String>();
     56         try {
     57             InputStream gtestResultStream1 = getClass().getResourceAsStream(File.separator +
     58                     TEST_TYPE_DIR + File.separator + filename);
     59             BufferedReader reader = new BufferedReader(new InputStreamReader(gtestResultStream1));
     60             String line = null;
     61             while ((line = reader.readLine()) != null) {
     62                 fileContents.add(line);
     63             }
     64         }
     65         catch (NullPointerException e) {
     66             CLog.e("Gest output file does not exist: " + filename);
     67         }
     68         catch (IOException e) {
     69             CLog.e("Unable to read contents of gtest output file: " + filename);
     70         }
     71         return fileContents.toArray(new String[fileContents.size()]);
     72     }
     73 }
     74