mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Clean up sdcard paths in tests
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
package com.keepassdroid.tests;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
@@ -26,12 +27,14 @@ import java.io.InputStream;
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
|
||||
import com.keepassdroid.utils.EmptyUtils;
|
||||
import com.keepassdroid.utils.UriUtil;
|
||||
|
||||
public class TestUtil {
|
||||
|
||||
private static final File sdcard = Environment.getExternalStorageDirectory();
|
||||
|
||||
public static void extractKey(Context ctx, String asset, String target) throws Exception {
|
||||
|
||||
InputStream key = ctx.getAssets().open(asset, AssetManager.ACCESS_STREAMING);
|
||||
@@ -60,4 +63,9 @@ public class TestUtil {
|
||||
|
||||
return keyIs;
|
||||
}
|
||||
|
||||
public static String getSdPath(String filename) {
|
||||
File file = new File(sdcard, filename);
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class Kdb4 extends AndroidTestCase {
|
||||
|
||||
byte[] data = bos.toByteArray();
|
||||
|
||||
FileOutputStream fos = new FileOutputStream("/sdcard/test-out.kdbx", false);
|
||||
FileOutputStream fos = new FileOutputStream(TestUtil.getSdPath("test-out.kdbx"), false);
|
||||
|
||||
InputStream bis = new ByteArrayInputStream(data);
|
||||
bis = new CopyInputStream(bis, fos);
|
||||
@@ -102,8 +102,8 @@ public class Kdb4 extends AndroidTestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
TestUtil.extractKey(getContext(), "keyfile.key", "/sdcard/key");
|
||||
TestUtil.extractKey(getContext(), "binary.key", "/sdcard/key-binary");
|
||||
TestUtil.extractKey(getContext(), "keyfile.key", TestUtil.getSdPath("key"));
|
||||
TestUtil.extractKey(getContext(), "binary.key", TestUtil.getSdPath("key-binary"));
|
||||
}
|
||||
|
||||
public void testComposite() throws IOException, InvalidDBException {
|
||||
@@ -113,7 +113,7 @@ public class Kdb4 extends AndroidTestCase {
|
||||
InputStream is = am.open("keyfile.kdbx", AssetManager.ACCESS_STREAMING);
|
||||
|
||||
ImporterV4 importer = new ImporterV4();
|
||||
importer.openDatabase(is, "12345", TestUtil.getKeyFileInputStream(ctx,"/sdcard/key"));
|
||||
importer.openDatabase(is, "12345", TestUtil.getKeyFileInputStream(ctx, TestUtil.getSdPath("key")));
|
||||
|
||||
is.close();
|
||||
|
||||
@@ -126,7 +126,7 @@ public class Kdb4 extends AndroidTestCase {
|
||||
InputStream is = am.open("keyfile-binary.kdbx", AssetManager.ACCESS_STREAMING);
|
||||
|
||||
ImporterV4 importer = new ImporterV4();
|
||||
importer.openDatabase(is, "12345", TestUtil.getKeyFileInputStream(ctx,"/sdcard/key-binary"));
|
||||
importer.openDatabase(is, "12345", TestUtil.getKeyFileInputStream(ctx,TestUtil.getSdPath("key-binary")));
|
||||
|
||||
is.close();
|
||||
|
||||
@@ -139,7 +139,7 @@ public class Kdb4 extends AndroidTestCase {
|
||||
InputStream is = am.open("key-only.kdbx", AssetManager.ACCESS_STREAMING);
|
||||
|
||||
ImporterV4 importer = new ImporterV4();
|
||||
importer.openDatabase(is, "", TestUtil.getKeyFileInputStream(ctx, "/sdcard/key"));
|
||||
importer.openDatabase(is, "", TestUtil.getKeyFileInputStream(ctx, TestUtil.getSdPath("key")));
|
||||
|
||||
is.close();
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ import com.keepassdroid.database.save.PwDbHeaderOutputV3;
|
||||
import com.keepassdroid.database.save.PwDbV3Output;
|
||||
import com.keepassdroid.database.save.PwDbV3OutputDebug;
|
||||
import com.keepassdroid.stream.NullOutputStream;
|
||||
import com.keepassdroid.tests.TestUtil;
|
||||
import com.keepassdroid.tests.database.TestData;
|
||||
|
||||
public class PwManagerOutputTest extends AndroidTestCase {
|
||||
@@ -136,7 +137,7 @@ public class PwManagerOutputTest extends AndroidTestCase {
|
||||
pActual.output();
|
||||
//pActual.close();
|
||||
|
||||
FileOutputStream fos = new FileOutputStream("/sdcard/test1_out.kdb");
|
||||
FileOutputStream fos = new FileOutputStream(TestUtil.getSdPath("test1_out.kdb"));
|
||||
fos.write(bActual.toByteArray());
|
||||
fos.close();
|
||||
assertArrayEquals("Databases do not match.", bExpected.toByteArray(), bActual.toByteArray());
|
||||
|
||||
Reference in New Issue
Block a user