diff options
author | Neal Nguyen <tommyn@google.com> | 2010-09-08 20:26:50 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-09-08 20:26:50 -0700 |
commit | 1e3187c27f878c083170149e645b1e2d19bc40a6 (patch) | |
tree | 59f7f9dce450aaf4934804e403a25ae7c86551de /core/tests/hosttests/src/android/content | |
parent | 515d2c1e95a95aa4502e318762d149adff57b6d3 (diff) | |
parent | 0c592acfc0ea298a0cf6c049cce4c5c10974e911 (diff) | |
download | frameworks_base-1e3187c27f878c083170149e645b1e2d19bc40a6.zip frameworks_base-1e3187c27f878c083170149e645b1e2d19bc40a6.tar.gz frameworks_base-1e3187c27f878c083170149e645b1e2d19bc40a6.tar.bz2 |
am 0c592acf: Merge "Adding Download Manager Integration, stress, and hosts-based tests." into gingerbread-plus-aosp
Merge commit '0c592acfc0ea298a0cf6c049cce4c5c10974e911'
* commit '0c592acfc0ea298a0cf6c049cce4c5c10974e911':
Adding Download Manager Integration, stress, and hosts-based tests.
Diffstat (limited to 'core/tests/hosttests/src/android/content')
-rw-r--r-- | core/tests/hosttests/src/android/content/pm/PackageManagerHostTestUtils.java | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/core/tests/hosttests/src/android/content/pm/PackageManagerHostTestUtils.java b/core/tests/hosttests/src/android/content/pm/PackageManagerHostTestUtils.java index 38191b0..c5ea9c1 100644 --- a/core/tests/hosttests/src/android/content/pm/PackageManagerHostTestUtils.java +++ b/core/tests/hosttests/src/android/content/pm/PackageManagerHostTestUtils.java @@ -37,7 +37,9 @@ import java.io.InputStreamReader; import java.io.StringReader; import java.lang.Runtime; import java.lang.Process; +import java.util.Hashtable; import java.util.Map; +import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -117,18 +119,38 @@ public class PackageManagerHostTestUtils extends Assert { /** * Helper method to run tests and return the listener that collected the results. + * + * For the optional params, pass null to use the default values. + * @param pkgName Android application package for tests - * @return the {@link CollectingTestRunListener} + * @param className (optional) The class containing the method to test + * @param methodName (optional) The method in the class of which to test + * @param runnerName (optional) The name of the TestRunner of the test on the device to be run + * @param params (optional) Any additional parameters to pass into the Test Runner * @throws TimeoutException in case of a timeout on the connection. * @throws AdbCommandRejectedException if adb rejects the command * @throws ShellCommandUnresponsiveException if the device did not output anything for * a period longer than the max time to output. * @throws IOException if connection to device was lost. + * @return the {@link CollectingTestRunListener} */ - private CollectingTestRunListener doRunTests(String pkgName) throws IOException, - TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException { - RemoteAndroidTestRunner testRunner = new RemoteAndroidTestRunner( - pkgName, mDevice); + private CollectingTestRunListener doRunTests(String pkgName, String className, + String methodName, String runnerName, Map<String, String> params) throws IOException, + TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException { + RemoteAndroidTestRunner testRunner = new RemoteAndroidTestRunner(pkgName, runnerName, + mDevice); + + if (className != null && methodName != null) { + testRunner.setMethodName(className, methodName); + } + + // Add in any additional args to pass into the test + if (params != null) { + for (Entry<String, String> argPair : params.entrySet()) { + testRunner.addInstrumentationArg(argPair.getKey(), argPair.getValue()); + } + } + CollectingTestRunListener listener = new CollectingTestRunListener(); try { testRunner.run(listener); @@ -142,16 +164,34 @@ public class PackageManagerHostTestUtils extends Assert { * Runs the specified packages tests, and returns whether all tests passed or not. * * @param pkgName Android application package for tests - * @return true if every test passed, false otherwise. + * @param className The class containing the method to test + * @param methodName The method in the class of which to test + * @param runnerName The name of the TestRunner of the test on the device to be run + * @param params Any additional parameters to pass into the Test Runner + * @return true if test passed, false otherwise. + */ + public boolean runDeviceTestsDidAllTestsPass(String pkgName, String className, + String methodName, String runnerName, Map<String, String> params) throws IOException, + TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException { + CollectingTestRunListener listener = doRunTests(pkgName, className, methodName, + runnerName, params); + return listener.didAllTestsPass(); + } + + /** + * Runs the specified packages tests, and returns whether all tests passed or not. + * + * @param pkgName Android application package for tests * @throws TimeoutException in case of a timeout on the connection. * @throws AdbCommandRejectedException if adb rejects the command * @throws ShellCommandUnresponsiveException if the device did not output anything for * a period longer than the max time to output. * @throws IOException if connection to device was lost. + * @return true if every test passed, false otherwise. */ public boolean runDeviceTestsDidAllTestsPass(String pkgName) throws IOException, TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException { - CollectingTestRunListener listener = doRunTests(pkgName); + CollectingTestRunListener listener = doRunTests(pkgName, null, null, null, null); return listener.didAllTestsPass(); } @@ -535,7 +575,7 @@ public class PackageManagerHostTestUtils extends Assert { } // For collecting results from running device tests - private static class CollectingTestRunListener implements ITestRunListener { + public static class CollectingTestRunListener implements ITestRunListener { private boolean mAllTestsPassed = true; private String mTestRunErrorMessage = null; |