blob: fe13e00498038877e680890e204f841d929c9d23 [file] [log] [blame]
The Android Open Source Projectf8057102009-03-15 16:47:16 -07001/*
2 * Copyright (C) 2008 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
Brian Muramatsu7f64e852011-02-17 16:52:16 -080017import org.w3c.dom.Document;
18import org.w3c.dom.Element;
19import org.w3c.dom.Node;
20import org.w3c.dom.NodeList;
21
22import vogar.Expectation;
23import vogar.ExpectationStore;
24import vogar.ModeId;
25
The Android Open Source Projectf8057102009-03-15 16:47:16 -070026import java.io.BufferedReader;
The Android Open Source Projectf8057102009-03-15 16:47:16 -070027import java.io.File;
28import java.io.FileInputStream;
Urs Grobfc77f6e2009-04-17 02:07:14 -070029import java.io.FileReader;
Brett Chabot5977e942010-12-13 16:42:42 -080030import java.io.FilenameFilter;
Urs Grobfc77f6e2009-04-17 02:07:14 -070031import java.io.IOException;
32import java.lang.annotation.Annotation;
The Android Open Source Projectf8057102009-03-15 16:47:16 -070033import java.lang.reflect.InvocationTargetException;
34import java.lang.reflect.Method;
Brian Carlstrom9f2dab82011-04-01 15:47:17 -070035import java.lang.reflect.Modifier;
The Android Open Source Projectf8057102009-03-15 16:47:16 -070036import java.util.ArrayList;
Brett Chabot5977e942010-12-13 16:42:42 -080037import java.util.Arrays;
Brian Carlstrom9f2dab82011-04-01 15:47:17 -070038import java.util.Enumeration;
The Android Open Source Projectf8057102009-03-15 16:47:16 -070039import java.util.HashSet;
40import java.util.Iterator;
Urs Grobfc77f6e2009-04-17 02:07:14 -070041import java.util.LinkedHashMap;
The Android Open Source Projectf8057102009-03-15 16:47:16 -070042import java.util.Map;
43import java.util.Set;
Brian Carlstrom9f2dab82011-04-01 15:47:17 -070044import java.util.jar.JarEntry;
45import java.util.jar.JarFile;
The Android Open Source Projectf8057102009-03-15 16:47:16 -070046
47import javax.xml.parsers.DocumentBuilderFactory;
48import javax.xml.parsers.ParserConfigurationException;
49
50import junit.framework.Test;
51import junit.framework.TestCase;
52import junit.framework.TestResult;
Urs Grobfc77f6e2009-04-17 02:07:14 -070053import junit.textui.ResultPrinter;
The Android Open Source Projectf8057102009-03-15 16:47:16 -070054import junit.textui.TestRunner;
55
The Android Open Source Projectf8057102009-03-15 16:47:16 -070056public class CollectAllTests extends DescriptionGenerator {
57
Brian Carlstrom022aff42011-05-17 23:16:51 -070058 private static final String ATTRIBUTE_RUNNER = "runner";
59 private static final String ATTRIBUTE_PACKAGE = "appPackageName";
60 private static final String ATTRIBUTE_NS = "appNameSpace";
61 private static final String ATTRIBUTE_TARGET = "targetNameSpace";
62 private static final String ATTRIBUTE_TARGET_BINARY = "targetBinaryName";
63 private static final String ATTRIBUTE_HOST_SIDE_ONLY = "hostSideOnly";
64 private static final String ATTRIBUTE_VM_HOST_TEST = "vmHostTest";
65 private static final String ATTRIBUTE_JAR_PATH = "jarPath";
66 private static final String ATTRIBUTE_JAVA_PACKAGE_FILTER = "javaPackageFilter";
The Android Open Source Projectf8057102009-03-15 16:47:16 -070067
Brian Carlstrom022aff42011-05-17 23:16:51 -070068 private static final String JAR_PATH = "LOCAL_JAR_PATH :=";
69 private static final String TEST_TYPE = "LOCAL_TEST_TYPE :";
The Android Open Source Projectf8057102009-03-15 16:47:16 -070070
71 public static void main(String[] args) {
Brian Carlstrom022aff42011-05-17 23:16:51 -070072 if (args.length < 4 || args.length > 6) {
73 System.err.println("usage: CollectAllTests <output-file> <manifest-file> <jar-file> "
74 + "<java-package> [expectation-dir [makefile-file]]");
75 if (args.length != 0) {
76 System.err.println("received:");
77 for (String arg : args) {
78 System.err.println(" " + arg);
Brian Carlstrom9f2dab82011-04-01 15:47:17 -070079 }
The Android Open Source Projectf8057102009-03-15 16:47:16 -070080 }
Urs Grobfc77f6e2009-04-17 02:07:14 -070081 System.exit(1);
The Android Open Source Projectf8057102009-03-15 16:47:16 -070082 }
83
Brian Carlstrom022aff42011-05-17 23:16:51 -070084 final String outputPathPrefix = args[0];
85 File manifestFile = new File(args[1]);
86 String jarFileName = args[2];
87 final String javaPackageFilter = args[3];
Tsu Chiang Chuangc87fd6b2011-07-13 17:04:40 -070088 // Validate the javaPackageFilter value if non null.
89 if (javaPackageFilter.length() != 0) {
90 if (!isValidJavaPackage(javaPackageFilter)) {
91 System.err.println("Invalid " + ATTRIBUTE_JAVA_PACKAGE_FILTER + ": " +
92 javaPackageFilter);
93 System.exit(1);
94 return;
95 }
96 }
Brian Carlstrom022aff42011-05-17 23:16:51 -070097 String libcoreExpectationDir = (args.length > 4) ? args[4] : null;
98 String androidMakeFile = (args.length > 5) ? args[5] : null;
The Android Open Source Projectf8057102009-03-15 16:47:16 -070099
Brian Carlstrom022aff42011-05-17 23:16:51 -0700100 final TestType testType = TestType.getTestType(androidMakeFile);
101
102 Document manifest;
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700103 try {
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700104 manifest = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
Brian Carlstrom022aff42011-05-17 23:16:51 -0700105 new FileInputStream(manifestFile));
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700106 } catch (Exception e) {
Brian Carlstrom022aff42011-05-17 23:16:51 -0700107 System.err.println("cannot open manifest " + manifestFile);
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700108 e.printStackTrace();
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700109 System.exit(1);
Brian Carlstrom022aff42011-05-17 23:16:51 -0700110 return;
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700111 }
112
113 Element documentElement = manifest.getDocumentElement();
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700114 documentElement.getAttribute("package");
Brian Carlstrom022aff42011-05-17 23:16:51 -0700115 final String runner = getElementAttribute(documentElement,
116 "instrumentation",
117 "android:name");
118 final String packageName = documentElement.getAttribute("package");
119 final String target = getElementAttribute(documentElement,
120 "instrumentation",
121 "android:targetPackage");
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700122
Brian Carlstrom022aff42011-05-17 23:16:51 -0700123 String outputXmlFile = outputPathPrefix + ".xml";
124 final String xmlName = new File(outputPathPrefix).getName();
125 XMLGenerator xmlGenerator;
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700126 try {
Brian Carlstrom022aff42011-05-17 23:16:51 -0700127 xmlGenerator = new XMLGenerator(outputXmlFile) {
128 {
129 Node testPackageElem = mDoc.getDocumentElement();
130
131 setAttribute(testPackageElem, ATTRIBUTE_NAME, xmlName);
132 setAttribute(testPackageElem, ATTRIBUTE_RUNNER, runner);
133 setAttribute(testPackageElem, ATTRIBUTE_PACKAGE, packageName);
134 setAttribute(testPackageElem, ATTRIBUTE_NS, packageName);
135 setAttribute(testPackageElem, ATTRIBUTE_JAVA_PACKAGE_FILTER, javaPackageFilter);
136
137 if (testType.type == TestType.HOST_SIDE_ONLY) {
138 setAttribute(testPackageElem, ATTRIBUTE_HOST_SIDE_ONLY, "true");
139 setAttribute(testPackageElem, ATTRIBUTE_JAR_PATH, testType.jarPath);
140 }
141
142 if (testType.type == TestType.VM_HOST_TEST) {
143 setAttribute(testPackageElem, ATTRIBUTE_VM_HOST_TEST, "true");
144 setAttribute(testPackageElem, ATTRIBUTE_JAR_PATH, testType.jarPath);
145 }
146
147 if (!packageName.equals(target)) {
148 setAttribute(testPackageElem, ATTRIBUTE_TARGET, target);
149 setAttribute(testPackageElem, ATTRIBUTE_TARGET_BINARY, target);
150 }
151 }
152 };
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700153 } catch (ParserConfigurationException e) {
Brian Carlstrom022aff42011-05-17 23:16:51 -0700154 System.err.println("Can't initialize XML Generator " + outputXmlFile);
Urs Grobfc77f6e2009-04-17 02:07:14 -0700155 System.exit(1);
Brian Carlstrom022aff42011-05-17 23:16:51 -0700156 return;
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700157 }
158
Brian Carlstrom022aff42011-05-17 23:16:51 -0700159 ExpectationStore libcoreVogarExpectationStore;
160 ExpectationStore ctsVogarExpectationStore;
161
Brett Chabot5977e942010-12-13 16:42:42 -0800162 try {
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700163 libcoreVogarExpectationStore
Brian Carlstrom022aff42011-05-17 23:16:51 -0700164 = VogarUtils.provideExpectationStore(libcoreExpectationDir);
Brian Muramatsu7f64e852011-02-17 16:52:16 -0800165 ctsVogarExpectationStore = VogarUtils.provideExpectationStore(CTS_EXPECTATION_DIR);
Brett Chabot5977e942010-12-13 16:42:42 -0800166 } catch (IOException e) {
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700167 System.err.println("Can't initialize vogar expectation store from "
Brian Carlstrom022aff42011-05-17 23:16:51 -0700168 + libcoreExpectationDir);
Brett Chabot5977e942010-12-13 16:42:42 -0800169 e.printStackTrace(System.err);
170 System.exit(1);
Brian Carlstrom022aff42011-05-17 23:16:51 -0700171 return;
Brett Chabot5977e942010-12-13 16:42:42 -0800172 }
Brian Carlstrom022aff42011-05-17 23:16:51 -0700173 ExpectationStore[] expectations = new ExpectationStore[] {
174 libcoreVogarExpectationStore, ctsVogarExpectationStore
175 };
Brett Chabot5977e942010-12-13 16:42:42 -0800176
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700177 JarFile jarFile = null;
178 try {
Brian Carlstrom022aff42011-05-17 23:16:51 -0700179 jarFile = new JarFile(jarFileName);
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700180 } catch (Exception e) {
Brian Carlstrom022aff42011-05-17 23:16:51 -0700181 System.err.println("cannot open jarfile " + jarFileName);
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700182 e.printStackTrace();
Urs Grobfc77f6e2009-04-17 02:07:14 -0700183 System.exit(1);
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700184 }
185
Brian Carlstrom022aff42011-05-17 23:16:51 -0700186 Map<String,TestClass> testCases = new LinkedHashMap<String, TestClass>();
187
188 String javaPackagePrefix = javaPackageFilter.isEmpty() ? "" : (javaPackageFilter + ".");
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700189
190 Enumeration<JarEntry> jarEntries = jarFile.entries();
191 while (jarEntries.hasMoreElements()) {
192 JarEntry jarEntry = jarEntries.nextElement();
193 String name = jarEntry.getName();
194 if (!name.endsWith(".class")) {
195 continue;
196 }
197 String className
198 = name.substring(0, name.length() - ".class".length()).replace('/', '.');
Brian Carlstrom022aff42011-05-17 23:16:51 -0700199 if (!className.startsWith(javaPackagePrefix)) {
200 continue;
201 }
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700202 try {
203 Class<?> klass = Class.forName(className,
204 false,
205 CollectAllTests.class.getClassLoader());
206 if (!TestCase.class.isAssignableFrom(klass)) {
207 continue;
208 }
209 if (Modifier.isAbstract(klass.getModifiers())) {
210 continue;
211 }
212 if (!Modifier.isPublic(klass.getModifiers())) {
213 continue;
214 }
215 try {
216 klass.getConstructor(new Class<?>[] { String.class } );
Brian Carlstrom022aff42011-05-17 23:16:51 -0700217 addToTests(expectations, testCases, klass.asSubclass(TestCase.class));
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700218 continue;
219 } catch (NoSuchMethodException e) {
Brian Carlstromd9f48462011-05-28 18:47:39 -0700220 } catch (SecurityException e) {
Tsu Chiang Chuangc87fd6b2011-07-13 17:04:40 -0700221 System.out.println("Known bug (Working as intended): problem with class "
222 + className);
Brian Carlstromd9f48462011-05-28 18:47:39 -0700223 e.printStackTrace();
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700224 }
225 try {
226 klass.getConstructor(new Class<?>[0]);
Brian Carlstrom022aff42011-05-17 23:16:51 -0700227 addToTests(expectations, testCases, klass.asSubclass(TestCase.class));
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700228 continue;
229 } catch (NoSuchMethodException e) {
Brian Carlstromd9f48462011-05-28 18:47:39 -0700230 } catch (SecurityException e) {
Tsu Chiang Chuangc87fd6b2011-07-13 17:04:40 -0700231 System.out.println("Known bug (Working as intended): problem with class "
232 + className);
Brian Carlstromd9f48462011-05-28 18:47:39 -0700233 e.printStackTrace();
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700234 }
235 } catch (ClassNotFoundException e) {
236 System.out.println("class not found " + className);
237 e.printStackTrace();
238 System.exit(1);
239 }
240 }
241
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700242 for (Iterator<TestClass> iterator = testCases.values().iterator(); iterator.hasNext();) {
243 TestClass type = iterator.next();
244 xmlGenerator.addTestClass(type);
245 }
246
247 try {
248 xmlGenerator.dump();
249 } catch (Exception e) {
Brian Carlstrom022aff42011-05-17 23:16:51 -0700250 System.err.println("cannot dump xml to " + outputXmlFile);
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700251 e.printStackTrace();
Urs Grobfc77f6e2009-04-17 02:07:14 -0700252 System.exit(1);
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700253 }
254 }
255
Brian Carlstrom022aff42011-05-17 23:16:51 -0700256 private static class TestType {
257 private static final int HOST_SIDE_ONLY = 1;
258 private static final int DEVICE_SIDE_ONLY = 2;
259 private static final int VM_HOST_TEST = 3;
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700260
Brian Carlstrom022aff42011-05-17 23:16:51 -0700261 private final int type;
262 private final String jarPath;
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700263
Brian Carlstrom022aff42011-05-17 23:16:51 -0700264 private TestType (int type, String jarPath) {
265 this.type = type;
266 this.jarPath = jarPath;
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700267 }
268
Brian Carlstrom022aff42011-05-17 23:16:51 -0700269 private static TestType getTestType(String makeFileName) {
270 if (makeFileName == null || makeFileName.isEmpty()) {
271 return new TestType(DEVICE_SIDE_ONLY, null);
272 }
273 int type = TestType.DEVICE_SIDE_ONLY;
274 String jarPath = null;
275 try {
276 BufferedReader reader = new BufferedReader(new FileReader(makeFileName));
277 String line;
278
279 while ((line =reader.readLine())!=null) {
280 if (line.startsWith(TEST_TYPE)) {
281 if (line.indexOf(ATTRIBUTE_VM_HOST_TEST) >= 0) {
282 type = VM_HOST_TEST;
283 } else {
284 type = HOST_SIDE_ONLY;
285 }
286 } else if (line.startsWith(JAR_PATH)) {
287 jarPath = line.substring(JAR_PATH.length(), line.length()).trim();
288 }
289 }
290 reader.close();
291 } catch (IOException e) {
292 }
293 return new TestType(type, jarPath);
294 }
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700295 }
296
297 private static Element getElement(Element element, String tagName) {
298 NodeList elements = element.getElementsByTagName(tagName);
299 if (elements.getLength() > 0) {
300 return (Element) elements.item(0);
301 } else {
302 return null;
303 }
304 }
305
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700306 private static String getElementAttribute(Element element,
307 String elementName,
308 String attributeName) {
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700309 Element e = getElement(element, elementName);
310 if (e != null) {
311 return e.getAttribute(attributeName);
312 } else {
313 return "";
314 }
315 }
316
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700317 private static String getKnownFailure(final Class<? extends TestCase> testClass,
Urs Grobfc77f6e2009-04-17 02:07:14 -0700318 final String testName) {
319 return getAnnotation(testClass, testName, KNOWN_FAILURE);
320 }
Brian Muramatsub8ed3162010-07-13 12:43:52 -0700321
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700322 private static boolean isKnownFailure(final Class<? extends TestCase> testClass,
Brian Muramatsub8ed3162010-07-13 12:43:52 -0700323 final String testName) {
324 return getAnnotation(testClass, testName, KNOWN_FAILURE) != null;
325 }
326
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700327 private static boolean isBrokenTest(final Class<? extends TestCase> testClass,
Urs Grobfc77f6e2009-04-17 02:07:14 -0700328 final String testName) {
329 return getAnnotation(testClass, testName, BROKEN_TEST) != null;
330 }
Brian Muramatsub8ed3162010-07-13 12:43:52 -0700331
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700332 private static boolean isSuppressed(final Class<? extends TestCase> testClass,
Brian Muramatsu168beb02010-10-21 12:39:45 -0700333 final String testName) {
334 return getAnnotation(testClass, testName, SUPPRESSED_TEST) != null;
335 }
336
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700337 private static boolean hasSideEffects(final Class<? extends TestCase> testClass,
Brian Muramatsu282c6fe2011-01-18 17:14:15 -0800338 final String testName) {
339 return getAnnotation(testClass, testName, SIDE_EFFECT) != null;
340 }
341
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700342 private static String getAnnotation(final Class<? extends TestCase> testClass,
Urs Grobfc77f6e2009-04-17 02:07:14 -0700343 final String testName, final String annotationName) {
The Android Open Source Project7671bec2009-03-19 23:08:36 -0700344 try {
Urs Grobfc77f6e2009-04-17 02:07:14 -0700345 Method testMethod = testClass.getMethod(testName, (Class[])null);
The Android Open Source Project7671bec2009-03-19 23:08:36 -0700346 Annotation[] annotations = testMethod.getAnnotations();
347 for (Annotation annot : annotations) {
348
Urs Grobfc77f6e2009-04-17 02:07:14 -0700349 if (annot.annotationType().getName().equals(annotationName)) {
The Android Open Source Project7671bec2009-03-19 23:08:36 -0700350 String annotStr = annot.toString();
351 String knownFailure = null;
352 if (annotStr.contains("(value=")) {
353 knownFailure =
Urs Grobfc77f6e2009-04-17 02:07:14 -0700354 annotStr.substring(annotStr.indexOf("=") + 1,
355 annotStr.length() - 1);
The Android Open Source Project7671bec2009-03-19 23:08:36 -0700356
357 }
358
359 if (knownFailure == null) {
360 knownFailure = "true";
361 }
362
363 return knownFailure;
364 }
365
366 }
367
Brian Carlstrom022aff42011-05-17 23:16:51 -0700368 } catch (NoSuchMethodException e) {
The Android Open Source Project7671bec2009-03-19 23:08:36 -0700369 }
370
371 return null;
372 }
373
Brian Carlstrom022aff42011-05-17 23:16:51 -0700374 private static void addToTests(ExpectationStore[] expectations,
375 Map<String,TestClass> testCases,
376 Class<? extends TestCase> test) {
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700377 Class testClass = test;
378 Set<String> testNames = new HashSet<String>();
379 while (TestCase.class.isAssignableFrom(testClass)) {
380 Method[] testMethods = testClass.getDeclaredMethods();
381 for (Method testMethod : testMethods) {
382 String testName = testMethod.getName();
383 if (testNames.contains(testName)) {
384 continue;
385 }
386 if (!testName.startsWith("test")) {
387 continue;
388 }
389 if (testMethod.getParameterTypes().length != 0) {
390 continue;
391 }
392 if (!testMethod.getReturnType().equals(Void.TYPE)) {
393 continue;
394 }
395 if (!Modifier.isPublic(testMethod.getModifiers())) {
396 continue;
397 }
398 testNames.add(testName);
Brian Carlstrom022aff42011-05-17 23:16:51 -0700399 addToTests(expectations, testCases, test, testName);
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700400 }
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700401 testClass = testClass.getSuperclass();
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700402 }
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700403 }
404
Brian Carlstrom022aff42011-05-17 23:16:51 -0700405 private static void addToTests(ExpectationStore[] expectations,
406 Map<String,TestClass> testCases,
407 Class<? extends TestCase> test,
408 String testName) {
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700409
410 String testClassName = test.getName();
411 String knownFailure = getKnownFailure(test, testName);
412
413 if (isKnownFailure(test, testName)) {
414 System.out.println("ignoring known failure: " + test + "#" + testName);
415 return;
416 } else if (isBrokenTest(test, testName)) {
417 System.out.println("ignoring broken test: " + test + "#" + testName);
418 return;
419 } else if (isSuppressed(test, testName)) {
420 System.out.println("ignoring suppressed test: " + test + "#" + testName);
421 return;
422 } else if (hasSideEffects(test, testName)) {
423 System.out.println("ignoring test with side effects: " + test + "#" + testName);
424 return;
Brian Carlstrom022aff42011-05-17 23:16:51 -0700425 } else if (VogarUtils.isVogarKnownFailure(expectations,
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700426 testClassName,
427 testName)) {
Brian Carlstrom022aff42011-05-17 23:16:51 -0700428 System.out.println("ignoring expectation known failure: " + test
Brian Carlstrom9f2dab82011-04-01 15:47:17 -0700429 + "#" + testName);
430 return;
431 }
432
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700433 TestClass testClass = null;
434 if (testCases.containsKey(testClassName)) {
435 testClass = testCases.get(testClassName);
436 } else {
437 testClass = new TestClass(testClassName, new ArrayList<TestMethod>());
438 testCases.put(testClassName, testClass);
439 }
440
Brian Muramatsu168beb02010-10-21 12:39:45 -0700441 testClass.mCases.add(new TestMethod(testName, "", "", knownFailure, false, false));
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700442 }
Tsu Chiang Chuangc87fd6b2011-07-13 17:04:40 -0700443
444 /**
445 * Determines if a given string is a valid java package name
446 * @param javaPackageName
447 * @return true if it is valid, false otherwise
448 */
449 private static boolean isValidJavaPackage(String javaPackageName) {
450 String[] strSections = javaPackageName.split(".");
451 for (String strSection : strSections) {
452 if (!isValidJavaIdentifier(strSection)) {
453 return false;
454 }
455 }
456 return true;
457 }
458
459 /**
460 * Determines if a given string is a valid java identifier.
461 * @param javaIdentifier
462 * @return true if it is a valid identifier, false otherwise
463 */
464 private static boolean isValidJavaIdentifier(String javaIdentifier) {
465 if (javaIdentifier.length() == 0 ||
466 !Character.isJavaIdentifierStart(javaIdentifier.charAt(0))) {
467 return false;
468 }
469 for (int i = 1; i < javaIdentifier.length(); i++) {
470 if (!Character.isJavaIdentifierPart(javaIdentifier.charAt(i))) {
471 return false;
472 }
473 }
474 return true;
475 }
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700476}