instrument: some updates to asymmetric decrypt tests

This commit is contained in:
Vincent Breitmoser
2015-06-22 03:16:32 +02:00
parent 361ad99928
commit 804a58e779
10 changed files with 624 additions and 14 deletions

View File

@@ -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();