aboutsummaryrefslogtreecommitdiff
path: root/dexmaker
diff options
context:
space:
mode:
authorPaul Duffin <paulduffin@google.com>2016-08-08 18:36:38 +0100
committerPaul Duffin <paulduffin@google.com>2016-08-09 15:52:01 +0100
commit9770a7ac2a5dd6d9374569740dad14b2a89af554 (patch)
tree7da5d80ec20f0353bf679fe3dc5f204837903aa7 /dexmaker
parentd6b8d02d4fc7d57f0b72dba598b6320ef02a8213 (diff)
downloaddexmaker-9770a7ac2a5dd6d9374569740dad14b2a89af554.tar.gz
Generate a test APK
Generates a test APK for use by the Android Continuous Testing Platform. Ensures that the selected data directory is writable when running the APK using am instrument. Bug: 30683723 Change-Id: I8129723f2b78aaa1a41808045e0d38980e8ba206 Test: Use vogar and am instrument as described in Android.mk
Diffstat (limited to 'dexmaker')
-rw-r--r--dexmaker/src/test/java/com/google/dexmaker/DexMakerTest.java13
-rw-r--r--dexmaker/src/test/java/com/google/dexmaker/stock/ProxyBuilderTest.java4
2 files changed, 16 insertions, 1 deletions
diff --git a/dexmaker/src/test/java/com/google/dexmaker/DexMakerTest.java b/dexmaker/src/test/java/com/google/dexmaker/DexMakerTest.java
index 2b7a27b..36e6c00 100644
--- a/dexmaker/src/test/java/com/google/dexmaker/DexMakerTest.java
+++ b/dexmaker/src/test/java/com/google/dexmaker/DexMakerTest.java
@@ -16,6 +16,7 @@
package com.google.dexmaker;
+import android.support.test.InstrumentationRegistry;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
@@ -2007,6 +2008,18 @@ public final class DexMakerTest extends TestCase {
}
public static File getDataDirectory() {
+ // Assume that this is being run as an APK by AndroidJUnitRunner and so get the directory
+ // where the APK can create files.
+ try {
+ // This will fail on Vogar as it will not register an Instrumentation.
+ return InstrumentationRegistry.getContext().getFilesDir();
+ } catch (IllegalStateException t) {
+ // Drop through to an alternate mechanism for getting a directory that works on Vogar.
+ if (!t.getMessage().contains("No instrumentation registered!")) {
+ // The exception wasn't expected.
+ throw t;
+ }
+ }
String envVariable = "ANDROID_DATA";
String defaultLoc = "/data";
String path = System.getenv(envVariable);
diff --git a/dexmaker/src/test/java/com/google/dexmaker/stock/ProxyBuilderTest.java b/dexmaker/src/test/java/com/google/dexmaker/stock/ProxyBuilderTest.java
index a959203..9c4cffe 100644
--- a/dexmaker/src/test/java/com/google/dexmaker/stock/ProxyBuilderTest.java
+++ b/dexmaker/src/test/java/com/google/dexmaker/stock/ProxyBuilderTest.java
@@ -37,7 +37,9 @@ public class ProxyBuilderTest extends TestCase {
public void setUp() throws Exception {
super.setUp();
- versionedDxDir.mkdirs();
+ if (!versionedDxDir.exists() && !versionedDxDir.mkdirs()) {
+ throw new IOException("Could not create " + versionedDxDir);
+ }
clearVersionedDxDir();
getGeneratedProxyClasses().clear();
}