• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.cts.nativescanner;
17 
18 import java.io.BufferedReader;
19 import java.io.InputStreamReader;
20 import java.util.Arrays;
21 import java.util.List;
22 
23 /**
24  * Class that searches a source directory for native gTests and outputs a
25  * list of test classes and methods.
26  */
27 public class CtsNativeScanner {
28 
usage(String[] args)29     private static void usage(String[] args) {
30         System.err.println("Arguments: " + Arrays.asList(args));
31         System.err.println("Usage: cts-native-scanner -t TEST_SUITE");
32         System.err.println("  This code reads from stdin the list of tests.");
33         System.err.println("  The format expected:");
34         System.err.println("    TEST_CASE_NAME.");
35         System.err.println("      TEST_NAME");
36         System.exit(1);
37     }
38 
main(String[] args)39     public static void main(String[] args) throws Exception {
40         String testSuite = null;
41         for (int i = 0; i < args.length; i++) {
42             if ("-t".equals(args[i])) {
43                 testSuite = getArg(args, ++i, "Missing value for test suite");
44             } else {
45                 System.err.println("Unsupported flag: " + args[i]);
46                 usage(args);
47             }
48         }
49 
50         if (testSuite == null) {
51             System.out.println("Test suite is required");
52             usage(args);
53         }
54 
55         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
56         TestScanner scanner = new TestScanner(reader, testSuite);
57         for (String name : scanner.getTestNames()) {
58             System.out.println(name);
59         }
60     }
61 
getArg(String[] args, int index, String message)62     private static String getArg(String[] args, int index, String message) {
63         if (index < args.length) {
64             return args[index];
65         } else {
66             System.err.println(message);
67             usage(args);
68             return null;
69         }
70     }
71 }
72