diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2014-06-24 18:14:14 -0700 |
---|---|---|
committer | Deepanshu Gupta <deepanshu@google.com> | 2014-07-01 12:22:13 -0700 |
commit | fe2a71bb13d65a2e8d6bcc60e6bda181029c78a0 (patch) | |
tree | 1f5c646665c005733a3993126513ec52be08617a | |
parent | 2416bab78b7a5295b2189700df75966e89cb123b (diff) | |
download | frameworks_base-fe2a71bb13d65a2e8d6bcc60e6bda181029c78a0.zip frameworks_base-fe2a71bb13d65a2e8d6bcc60e6bda181029c78a0.tar.gz frameworks_base-fe2a71bb13d65a2e8d6bcc60e6bda181029c78a0.tar.bz2 |
Report all TestDelegate failures in a single run.
Change-Id: I37fa0a6f300ea89c8d0a60380b77b7d61db01cb7
-rw-r--r-- | tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/TestDelegates.java | 84 |
1 files changed, 49 insertions, 35 deletions
diff --git a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/TestDelegates.java b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/TestDelegates.java index 274516c..8b362ec 100644 --- a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/TestDelegates.java +++ b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/TestDelegates.java @@ -41,27 +41,29 @@ import junit.framework.TestCase; */ public class TestDelegates extends TestCase { + private List<String> mErrors = new ArrayList<String>(); + public void testNativeDelegates() { final String[] classes = CreateInfo.DELEGATE_CLASS_NATIVES; - final int count = classes.length; - for (int i = 0 ; i < count ; i++) { - loadAndCompareClasses(classes[i], classes[i] + "_Delegate"); + mErrors.clear(); + for (String clazz : classes) { + loadAndCompareClasses(clazz, clazz + "_Delegate"); } + assertTrue(getErrors(), mErrors.isEmpty()); } public void testMethodDelegates() { final String[] methods = CreateInfo.DELEGATE_METHODS; - final int count = methods.length; - for (int i = 0 ; i < count ; i++) { - String methodName = methods[i]; - + mErrors.clear(); + for (String methodName : methods) { // extract the class name String className = methodName.substring(0, methodName.indexOf('#')); String targetClassName = className.replace('$', '_') + "_Delegate"; loadAndCompareClasses(className, targetClassName); } + assertTrue(getErrors(), mErrors.isEmpty()); } private void loadAndCompareClasses(String originalClassName, String delegateClassName) { @@ -73,9 +75,9 @@ public class TestDelegates extends TestCase { compare(originalClass, delegateClass); } catch (ClassNotFoundException e) { - fail("Failed to load class: " + e.getMessage()); + mErrors.add("Failed to load class: " + e.getMessage()); } catch (SecurityException e) { - fail("Failed to load class: " + e.getMessage()); + mErrors.add("Failed to load class: " + e.getMessage()); } } @@ -122,35 +124,39 @@ public class TestDelegates extends TestCase { parameters); // check the return type of the methods match. - assertTrue( - String.format("Delegate method %1$s.%2$s does not match the corresponding " + - "framework method which returns %3$s", - delegateClass.getName(), - getMethodName(delegateMethod), - originalMethod.getReturnType().getName()), - delegateMethod.getReturnType() == originalMethod.getReturnType()); + if (delegateMethod.getReturnType() != originalMethod.getReturnType()) { + mErrors.add( + String.format("Delegate method %1$s.%2$s does not match the " + + "corresponding framework method which returns %3$s", + delegateClass.getName(), + getMethodName(delegateMethod), + originalMethod.getReturnType().getName())); + } // check that the method has the annotation - assertNotNull( - String.format( - "Delegate method %1$s for class %2$s does not have the @LayoutlibDelegate annotation", - delegateMethod.getName(), - originalClass.getName()), - delegateMethod.getAnnotation(LayoutlibDelegate.class)); + if (delegateMethod.getAnnotation(LayoutlibDelegate.class) == null) { + mErrors.add( + String.format("Delegate method %1$s for class %2$s does not have the " + + "@LayoutlibDelegate annotation", + delegateMethod.getName(), + originalClass.getName())); + } // check that the method is static - assertTrue( - String.format( - "Delegate method %1$s for class %2$s is not static", - delegateMethod.getName(), - originalClass.getName()), - (delegateMethod.getModifiers() & Modifier.STATIC) == Modifier.STATIC); + if ((delegateMethod.getModifiers() & Modifier.STATIC) != Modifier.STATIC) { + mErrors.add( + String.format( + "Delegate method %1$s for class %2$s is not static", + delegateMethod.getName(), + originalClass.getName()) + ); + } // add the method as checked. checkedDelegateMethods.add(delegateMethod); } catch (NoSuchMethodException e) { String name = getMethodName(originalMethod, parameters); - fail(String.format("Missing %1$s.%2$s", delegateClass.getName(), name)); + mErrors.add(String.format("Missing %1$s.%2$s", delegateClass.getName(), name)); } } @@ -167,12 +173,12 @@ public class TestDelegates extends TestCase { continue; } - assertTrue( - String.format( - "Delegate method %1$s.%2$s is not used anymore and must be removed", - delegateClass.getName(), - getMethodName(delegateMethod)), - checkedDelegateMethods.contains(delegateMethod)); + if (!checkedDelegateMethods.contains(delegateMethod)) { + mErrors.add(String.format( + "Delegate method %1$s.%2$s is not used anymore and must be removed", + delegateClass.getName(), + getMethodName(delegateMethod))); + } } } @@ -203,4 +209,12 @@ public class TestDelegates extends TestCase { return sb.toString(); } + + private String getErrors() { + StringBuilder s = new StringBuilder(); + for (String error : mErrors) { + s.append(error).append('\n'); + } + return s.toString(); + } } |