aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-06-22 03:16:32 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2015-06-22 03:16:32 +0200
commit804a58e779e8bbb5c8c2d53211626dcfd5556ed7 (patch)
treee61d6e3b75f7bafe0d1da58046242f570e84eb86 /OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java
parent361ad99928589b19b2cc1d73b2f27e7060cd21b2 (diff)
downloadopen-keychain-804a58e779e8bbb5c8c2d53211626dcfd5556ed7.tar.gz
open-keychain-804a58e779e8bbb5c8c2d53211626dcfd5556ed7.tar.bz2
open-keychain-804a58e779e8bbb5c8c2d53211626dcfd5556ed7.zip
instrument: some updates to asymmetric decrypt tests
Diffstat (limited to 'OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java')
-rw-r--r--OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java40
1 files changed, 39 insertions, 1 deletions
diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java
index 4c058940b..bbf69f73e 100644
--- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java
+++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java
@@ -18,6 +18,13 @@
package org.sufficientlysecure.keychain;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.Random;
import android.content.Context;
@@ -55,7 +62,7 @@ public class TestHelpers {
}
- static void importKeysFromResource(Context context, String name) throws Exception {
+ public static void importKeysFromResource(Context context, String name) throws Exception {
IteratorWithIOThrow<UncachedKeyRing> stream = UncachedKeyRing.fromStream(
getInstrumentation().getContext().getAssets().open(name));
@@ -71,6 +78,37 @@ public class TestHelpers {
}
+ public static void copyFiles() throws IOException {
+ File cacheDir = getInstrumentation().getTargetContext().getFilesDir();
+ byte[] buf = new byte[256];
+ for (String filename : FILES) {
+ File outFile = new File(cacheDir, filename);
+ if (outFile.exists()) {
+ continue;
+ }
+ InputStream in = new BufferedInputStream(getInstrumentation().getContext().getAssets().open(filename));
+ OutputStream out = new BufferedOutputStream(new FileOutputStream(outFile));
+ int len;
+ while( (len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ }
+ }
+
+ public static final String[] FILES = new String[] { "pa.png", "re.png", "ci.png" };
+ public static File[] getImageNames() {
+ File cacheDir = getInstrumentation().getTargetContext().getFilesDir();
+ File[] ret = new File[FILES.length];
+ for (int i = 0; i < ret.length; i++) {
+ ret[i] = new File(cacheDir, FILES[i]);
+ }
+ return ret;
+ }
+
+ public static <T> T pickRandom(T[] haystack) {
+ return haystack[new Random().nextInt(haystack.length)];
+ }
+
public static String randomString(int min, int max) {
String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789!@#$%^&*()-_=";
Random r = new Random();