summaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java')
-rw-r--r--tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java82
1 files changed, 51 insertions, 31 deletions
diff --git a/tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java b/tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java
index ad603df39..51375e139 100644
--- a/tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java
+++ b/tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java
@@ -19,6 +19,8 @@ package com.android.gallery3d.exif;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -26,48 +28,66 @@ import java.io.IOException;
import java.io.InputStream;
public class ExifOutputStreamTest extends ExifXmlDataTestCase {
- public ExifOutputStreamTest(int imageResourceId, int xmlResourceId) {
- super(imageResourceId, xmlResourceId);
+ public ExifOutputStreamTest(int imgRes, int xmlRes) {
+ super(imgRes, xmlRes);
}
- public void testExifOutputStream() throws IOException, ExifInvalidFormatException {
+ public ExifOutputStreamTest(String imgPath, String xmlPath) {
+ super(imgPath, xmlPath);
+ }
+
+ public void testExifOutputStream() throws Exception {
File file = File.createTempFile("exif_test", ".jpg");
InputStream imageInputStream = null;
InputStream exifInputStream = null;
FileInputStream reDecodeInputStream = null;
FileInputStream reParseInputStream = null;
try {
- // Read the image
- imageInputStream = getInstrumentation()
- .getContext().getResources().openRawResource(mImageResourceId);
- Bitmap bmp = BitmapFactory.decodeStream(imageInputStream);
+ try {
+ byte[] imgData = readToByteArray(getImageInputStream());
+ imageInputStream = new ByteArrayInputStream(imgData);
+ exifInputStream = new ByteArrayInputStream(imgData);
+
+ // Read the image data
+ Bitmap bmp = BitmapFactory.decodeStream(imageInputStream);
+ // Read exif data
+ ExifData exifData = new ExifReader().read(exifInputStream);
- // Read exif data
- exifInputStream = getInstrumentation()
- .getContext().getResources().openRawResource(mImageResourceId);
- ExifData exifData = new ExifReader().read(exifInputStream);
+ // Encode the image with the exif data
+ FileOutputStream outputStream = new FileOutputStream(file);
+ ExifOutputStream exifOutputStream = new ExifOutputStream(outputStream);
+ exifOutputStream.setExifData(exifData);
+ bmp.compress(Bitmap.CompressFormat.JPEG, 100, exifOutputStream);
+ exifOutputStream.close();
- // Encode the image with the exif data
- FileOutputStream outputStream = new FileOutputStream(file);
- ExifOutputStream exifOutputStream = new ExifOutputStream(outputStream);
- exifOutputStream.setExifData(exifData);
- bmp.compress(Bitmap.CompressFormat.JPEG, 100, exifOutputStream);
- exifOutputStream.close();
+ // Re-decode the temp file and check the data.
+ reDecodeInputStream = new FileInputStream(file);
+ Bitmap decodedBmp = BitmapFactory.decodeStream(reDecodeInputStream);
+ assertNotNull(decodedBmp);
- // Re-decode the temp file and check the data.
- reDecodeInputStream = new FileInputStream(file);
- Bitmap decodedBmp = BitmapFactory.decodeStream(reDecodeInputStream);
- assertNotNull(decodedBmp);
+ // Re-parse the temp file the check EXIF tag
+ reParseInputStream = new FileInputStream(file);
+ ExifData reExifData = new ExifReader().read(reParseInputStream);
+ assertEquals(exifData, reExifData);
+ } finally {
+ Util.closeSilently(imageInputStream);
+ Util.closeSilently(exifInputStream);
+ Util.closeSilently(reDecodeInputStream);
+ Util.closeSilently(reParseInputStream);
+ }
+ } catch (Exception e) {
+ throw new Exception(getImageTitle(), e);
+ }
+ }
- // Re-parse the temp file the check EXIF tag
- reParseInputStream = new FileInputStream(file);
- ExifData reExifData = new ExifReader().read(reParseInputStream);
- assertEquals(exifData, reExifData);
- } finally {
- Util.closeSilently(imageInputStream);
- Util.closeSilently(exifInputStream);
- Util.closeSilently(reDecodeInputStream);
- Util.closeSilently(reParseInputStream);
+ private byte[] readToByteArray(InputStream is) throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ int len;
+ byte[] buf = new byte[1024];
+ while ((len = is.read(buf)) > -1) {
+ bos.write(buf, 0, len);
}
+ bos.flush();
+ return bos.toByteArray();
}
-} \ No newline at end of file
+}