mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
[android] add instrumentation test for image compression
This commit is contained in:
BIN
briar-android/src/androidTestOfficial/assets/blue-500x500.png
Normal file
BIN
briar-android/src/androidTestOfficial/assets/blue-500x500.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
BIN
briar-android/src/androidTestOfficial/assets/green-1000x2000.png
Normal file
BIN
briar-android/src/androidTestOfficial/assets/green-1000x2000.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
BIN
briar-android/src/androidTestOfficial/assets/red-100x100.png
Normal file
BIN
briar-android/src/androidTestOfficial/assets/red-100x100.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 755 B |
@@ -0,0 +1,67 @@
|
||||
package org.briarproject.briar.android.attachment;
|
||||
|
||||
import android.content.res.AssetManager;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import static androidx.test.InstrumentationRegistry.getContext;
|
||||
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class AttachmentCreationTaskTest {
|
||||
|
||||
private static Logger LOG =
|
||||
getLogger(AttachmentCreationTaskTest.class.getName());
|
||||
|
||||
private final ImageHelper imageHelper = new ImageHelperImpl();
|
||||
private final ImageSizeCalculator imageSizeCalculator =
|
||||
new ImageSizeCalculator(imageHelper);
|
||||
@SuppressWarnings("ConstantConditions") // add real objects when needed
|
||||
private final AttachmentCreationTask task = new AttachmentCreationTask(null,
|
||||
getApplicationContext().getContentResolver(), null,
|
||||
imageSizeCalculator, null, null, true);
|
||||
|
||||
@Test
|
||||
public void testCompress() throws Exception {
|
||||
InputStream is = getAssetInputStream("animated.gif");
|
||||
task.compressImage(is, "image/gif");
|
||||
|
||||
is = getAssetInputStream("animated2.gif");
|
||||
task.compressImage(is, "image/gif");
|
||||
|
||||
is = getAssetInputStream("blue-500x500.png");
|
||||
task.compressImage(is, "image/png");
|
||||
|
||||
is = getAssetInputStream("error_high.jpg");
|
||||
task.compressImage(is, "image/jpeg");
|
||||
|
||||
is = getAssetInputStream("error_large.gif");
|
||||
task.compressImage(is, "image/gif");
|
||||
|
||||
is = getAssetInputStream("error_wide.jpg");
|
||||
task.compressImage(is, "image/jpeg");
|
||||
|
||||
is = getAssetInputStream("green-1000x2000.png");
|
||||
task.compressImage(is, "image/png");
|
||||
|
||||
is = getAssetInputStream("red-100x100.png");
|
||||
task.compressImage(is, "image/png");
|
||||
}
|
||||
|
||||
private InputStream getAssetInputStream(String name) throws IOException {
|
||||
LOG.warning("getAssetInputStream: " + name);
|
||||
// pm.getResourcesForApplication(packageName).getAssets() did not work
|
||||
//noinspection deprecation
|
||||
AssetManager assets = getContext().getAssets();
|
||||
return assets.open(name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import java.util.Collection;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import static android.graphics.Bitmap.CompressFormat.JPEG;
|
||||
import static android.graphics.BitmapFactory.decodeStream;
|
||||
@@ -130,7 +131,8 @@ class AttachmentCreationTask {
|
||||
return false;
|
||||
}
|
||||
|
||||
private InputStream compressImage(InputStream is, String contentType)
|
||||
@VisibleForTesting
|
||||
InputStream compressImage(InputStream is, String contentType)
|
||||
throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user