summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEarl Ou <shunhsingou@google.com>2012-10-18 14:46:42 +0800
committerEarl Ou <shunhsingou@google.com>2012-10-18 15:12:20 +0800
commitb677dc86dd209b1a7632f934892a635d495d329d (patch)
treed02e96754ff518bc3c48dce212c4dae2f0686be8 /tests
parentaa8ef6ace8f8a42682be1f71a4d1c631e8ebf22f (diff)
downloadandroid_packages_apps_Snap-b677dc86dd209b1a7632f934892a635d495d329d.zip
android_packages_apps_Snap-b677dc86dd209b1a7632f934892a635d495d329d.tar.gz
android_packages_apps_Snap-b677dc86dd209b1a7632f934892a635d495d329d.tar.bz2
Print image path for exception in Exif test
Change-Id: Ib5b502ea91c9fb14dbd9e0ede664136943e50401
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java58
-rw-r--r--tests/src/com/android/gallery3d/exif/ExifParserTest.java242
-rw-r--r--tests/src/com/android/gallery3d/exif/ExifReaderTest.java16
3 files changed, 168 insertions, 148 deletions
diff --git a/tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java b/tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java
index 1950c7e..51375e1 100644
--- a/tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java
+++ b/tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java
@@ -26,8 +26,6 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.List;
-import java.util.Map;
public class ExifOutputStreamTest extends ExifXmlDataTestCase {
public ExifOutputStreamTest(int imgRes, int xmlRes) {
@@ -45,36 +43,40 @@ public class ExifOutputStreamTest extends ExifXmlDataTestCase {
FileInputStream reDecodeInputStream = null;
FileInputStream reParseInputStream = null;
try {
- byte[] imgData = readToByteArray(getImageInputStream());
- imageInputStream = new ByteArrayInputStream(imgData);
- exifInputStream = new ByteArrayInputStream(imgData);
+ 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 the image data
+ Bitmap bmp = BitmapFactory.decodeStream(imageInputStream);
+ // Read exif data
+ 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);
+ // 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);
}
}
diff --git a/tests/src/com/android/gallery3d/exif/ExifParserTest.java b/tests/src/com/android/gallery3d/exif/ExifParserTest.java
index fccf261..38b1f2f 100644
--- a/tests/src/com/android/gallery3d/exif/ExifParserTest.java
+++ b/tests/src/com/android/gallery3d/exif/ExifParserTest.java
@@ -19,7 +19,6 @@ package com.android.gallery3d.exif;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import java.io.IOException;
import java.util.List;
import java.util.Map;
@@ -43,31 +42,35 @@ public class ExifParserTest extends ExifXmlDataTestCase {
}
public void testParse() throws Exception {
- ExifParser parser = ExifParser.parse(getImageInputStream());
- int event = parser.next();
- while (event != ExifParser.EVENT_END) {
- switch (event) {
- case ExifParser.EVENT_START_OF_IFD:
- break;
- case ExifParser.EVENT_NEW_TAG:
- ExifTag tag = parser.getTag();
- if (!tag.hasValue()) {
- parser.registerForTagValue(tag);
- } else {
+ try {
+ ExifParser parser = ExifParser.parse(getImageInputStream());
+ int event = parser.next();
+ while (event != ExifParser.EVENT_END) {
+ switch (event) {
+ case ExifParser.EVENT_START_OF_IFD:
+ break;
+ case ExifParser.EVENT_NEW_TAG:
+ ExifTag tag = parser.getTag();
+ if (!tag.hasValue()) {
+ parser.registerForTagValue(tag);
+ } else {
+ checkTag(tag);
+ }
+ break;
+ case ExifParser.EVENT_VALUE_OF_REGISTERED_TAG:
+ tag = parser.getTag();
+ if (tag.getDataType() == ExifTag.TYPE_UNDEFINED) {
+ byte[] buf = new byte[tag.getComponentCount()];
+ parser.read(buf);
+ tag.setValue(buf);
+ }
checkTag(tag);
- }
- break;
- case ExifParser.EVENT_VALUE_OF_REGISTERED_TAG:
- tag = parser.getTag();
- if (tag.getDataType() == ExifTag.TYPE_UNDEFINED) {
- byte[] buf = new byte[tag.getComponentCount()];
- parser.read(buf);
- tag.setValue(buf);
- }
- checkTag(tag);
- break;
+ break;
+ }
+ event = parser.next();
}
- event = parser.next();
+ } catch (Exception e) {
+ throw new Exception(getImageTitle(), e);
}
}
@@ -80,7 +83,7 @@ public class ExifParserTest extends ExifXmlDataTestCase {
if (tag.getTagId() == ExifTag.TAG_MAKER_NOTE
|| tag.getTagId() == ExifTag.TAG_USER_COMMENT) return;
- String truthString = mGroundTruth.get(tag.getIfd()).get(tag.getTagId()).trim();
+ String truthString = mGroundTruth.get(tag.getIfd()).get(tag.getTagId());
if (truthString == null) {
fail(String.format("Unknown Tag %02x", tag.getTagId()) + ", " + getImageTitle());
@@ -88,48 +91,51 @@ public class ExifParserTest extends ExifXmlDataTestCase {
String dataString = tag.valueToString().trim();
assertEquals(String.format("Tag %02x", tag.getTagId()) + ", " + getImageTitle(),
- truthString, dataString);
+ truthString.trim(), dataString);
}
- private void parseOneIfd(int ifd, int options)
- throws IOException, ExifInvalidFormatException {
- Map<Short, String> expectedResult = mGroundTruth.get(ifd);
- int numOfTag = 0;
- ExifParser parser = ExifParser.parse(getImageInputStream(), options);
- int event = parser.next();
- while(event != ExifParser.EVENT_END) {
- switch (event) {
- case ExifParser.EVENT_START_OF_IFD:
- assertEquals(getImageTitle(), ifd, parser.getCurrentIfd());
- break;
- case ExifParser.EVENT_NEW_TAG:
- ExifTag tag = parser.getTag();
- // The exiftool doesn't provide MakerNote tag
- if (!ExifTag.isSubIfdOffsetTag(tag.getTagId())
- && tag.getTagId() != ExifTag.TAG_MAKER_NOTE) numOfTag++;
- if (tag.hasValue()) {
+ private void parseOneIfd(int ifd, int options) throws Exception {
+ try {
+ Map<Short, String> expectedResult = mGroundTruth.get(ifd);
+ int numOfTag = 0;
+ ExifParser parser = ExifParser.parse(getImageInputStream(), options);
+ int event = parser.next();
+ while(event != ExifParser.EVENT_END) {
+ switch (event) {
+ case ExifParser.EVENT_START_OF_IFD:
+ assertEquals(getImageTitle(), ifd, parser.getCurrentIfd());
+ break;
+ case ExifParser.EVENT_NEW_TAG:
+ ExifTag tag = parser.getTag();
+ // The exiftool doesn't provide MakerNote tag
+ if (!ExifTag.isSubIfdOffsetTag(tag.getTagId())
+ && tag.getTagId() != ExifTag.TAG_MAKER_NOTE) numOfTag++;
+ if (tag.hasValue()) {
+ checkTag(tag);
+ } else {
+ parser.registerForTagValue(tag);
+ }
+ break;
+ case ExifParser.EVENT_VALUE_OF_REGISTERED_TAG:
+ tag = parser.getTag();
+ if (tag.getDataType() == ExifTag.TYPE_UNDEFINED) {
+ byte[] buf = new byte[tag.getComponentCount()];
+ parser.read(buf);
+ tag.setValue(buf);
+ }
checkTag(tag);
- } else {
- parser.registerForTagValue(tag);
- }
- break;
- case ExifParser.EVENT_VALUE_OF_REGISTERED_TAG:
- tag = parser.getTag();
- if (tag.getDataType() == ExifTag.TYPE_UNDEFINED) {
- byte[] buf = new byte[tag.getComponentCount()];
- parser.read(buf);
- tag.setValue(buf);
- }
- checkTag(tag);
- break;
- case ExifParser.EVENT_COMPRESSED_IMAGE:
- case ExifParser.EVENT_UNCOMPRESSED_STRIP:
- fail("Invalid Event type: " + event + ", " + getImageTitle());
- break;
+ break;
+ case ExifParser.EVENT_COMPRESSED_IMAGE:
+ case ExifParser.EVENT_UNCOMPRESSED_STRIP:
+ fail("Invalid Event type: " + event + ", " + getImageTitle());
+ break;
+ }
+ event = parser.next();
}
- event = parser.next();
+ assertEquals(expectedResult.size(), numOfTag);
+ } catch (Exception e) {
+ throw new Exception(getImageTitle(), e);
}
- assertEquals(expectedResult.size(), numOfTag);
}
public void testOnlyExifIfd() throws Exception {
@@ -149,66 +155,74 @@ public class ExifParserTest extends ExifXmlDataTestCase {
}
public void testOnlyReadSomeTag() throws Exception {
- ExifParser parser = ExifParser.parse(getImageInputStream(), ExifParser.OPTION_IFD_0);
- int event = parser.next();
- boolean isTagFound = false;
- while (event != ExifParser.EVENT_END) {
- switch (event) {
- case ExifParser.EVENT_START_OF_IFD:
- assertEquals(getImageTitle(), IfdId.TYPE_IFD_0, parser.getCurrentIfd());
- break;
- case ExifParser.EVENT_NEW_TAG:
- ExifTag tag = parser.getTag();
- if (tag.getTagId() == ExifTag.TAG_MODEL) {
- if (tag.hasValue()) {
- isTagFound = true;
- checkTag(tag);
- } else {
- parser.registerForTagValue(tag);
+ try {
+ ExifParser parser = ExifParser.parse(getImageInputStream(), ExifParser.OPTION_IFD_0);
+ int event = parser.next();
+ boolean isTagFound = false;
+ while (event != ExifParser.EVENT_END) {
+ switch (event) {
+ case ExifParser.EVENT_START_OF_IFD:
+ assertEquals(getImageTitle(), IfdId.TYPE_IFD_0, parser.getCurrentIfd());
+ break;
+ case ExifParser.EVENT_NEW_TAG:
+ ExifTag tag = parser.getTag();
+ if (tag.getTagId() == ExifTag.TAG_MODEL) {
+ if (tag.hasValue()) {
+ isTagFound = true;
+ checkTag(tag);
+ } else {
+ parser.registerForTagValue(tag);
+ }
+ parser.skipRemainingTagsInCurrentIfd();
}
- parser.skipRemainingTagsInCurrentIfd();
- }
- break;
- case ExifParser.EVENT_VALUE_OF_REGISTERED_TAG:
- tag = parser.getTag();
- assertEquals(getImageTitle(), ExifTag.TAG_MODEL, tag.getTagId());
- checkTag(tag);
- isTagFound = true;
- break;
+ break;
+ case ExifParser.EVENT_VALUE_OF_REGISTERED_TAG:
+ tag = parser.getTag();
+ assertEquals(getImageTitle(), ExifTag.TAG_MODEL, tag.getTagId());
+ checkTag(tag);
+ isTagFound = true;
+ break;
+ }
+ event = parser.next();
}
- event = parser.next();
+ assertTrue(getImageTitle(), isTagFound);
+ } catch (Exception e) {
+ throw new Exception(getImageTitle(), e);
}
- assertTrue(getImageTitle(), isTagFound);
}
public void testReadThumbnail() throws Exception {
- ExifParser parser = ExifParser.parse(getImageInputStream(),
- ExifParser.OPTION_IFD_1 | ExifParser.OPTION_THUMBNAIL);
-
- int event = parser.next();
- Bitmap bmp = null;
- boolean mIsContainCompressedImage = false;
- while (event != ExifParser.EVENT_END) {
- switch (event) {
- case ExifParser.EVENT_NEW_TAG:
- ExifTag tag = parser.getTag();
- if (tag.getTagId() == ExifTag.TAG_COMPRESSION) {
- if (tag.getUnsignedShort(0) == ExifTag.Compression.JPEG) {
- mIsContainCompressedImage = true;
+ try {
+ ExifParser parser = ExifParser.parse(getImageInputStream(),
+ ExifParser.OPTION_IFD_1 | ExifParser.OPTION_THUMBNAIL);
+
+ int event = parser.next();
+ Bitmap bmp = null;
+ boolean mIsContainCompressedImage = false;
+ while (event != ExifParser.EVENT_END) {
+ switch (event) {
+ case ExifParser.EVENT_NEW_TAG:
+ ExifTag tag = parser.getTag();
+ if (tag.getTagId() == ExifTag.TAG_COMPRESSION) {
+ if (tag.getUnsignedShort(0) == ExifTag.Compression.JPEG) {
+ mIsContainCompressedImage = true;
+ }
}
- }
- break;
- case ExifParser.EVENT_COMPRESSED_IMAGE:
- int imageSize = parser.getCompressedImageSize();
- byte buf[] = new byte[imageSize];
- parser.read(buf);
- bmp = BitmapFactory.decodeByteArray(buf, 0, imageSize);
- break;
+ break;
+ case ExifParser.EVENT_COMPRESSED_IMAGE:
+ int imageSize = parser.getCompressedImageSize();
+ byte buf[] = new byte[imageSize];
+ parser.read(buf);
+ bmp = BitmapFactory.decodeByteArray(buf, 0, imageSize);
+ break;
+ }
+ event = parser.next();
}
- event = parser.next();
- }
- if (mIsContainCompressedImage) {
- assertNotNull(getImageTitle(), bmp);
+ if (mIsContainCompressedImage) {
+ assertNotNull(getImageTitle(), bmp);
+ }
+ } catch (Exception e) {
+ throw new Exception(getImageTitle(), e);
}
}
}
diff --git a/tests/src/com/android/gallery3d/exif/ExifReaderTest.java b/tests/src/com/android/gallery3d/exif/ExifReaderTest.java
index c753df6..6a884ea 100644
--- a/tests/src/com/android/gallery3d/exif/ExifReaderTest.java
+++ b/tests/src/com/android/gallery3d/exif/ExifReaderTest.java
@@ -33,13 +33,17 @@ public class ExifReaderTest extends ExifXmlDataTestCase {
}
public void testRead() throws Exception {
- ExifReader reader = new ExifReader();
- ExifData exifData = reader.read(getImageInputStream());
- List<Map<Short, String>> groundTruth = ExifXmlReader.readXml(getXmlParser());
- for (int i = 0; i < IfdId.TYPE_IFD_COUNT; i++) {
- checkIfd(exifData.getIfdData(i), groundTruth.get(i));
+ try {
+ ExifReader reader = new ExifReader();
+ ExifData exifData = reader.read(getImageInputStream());
+ List<Map<Short, String>> groundTruth = ExifXmlReader.readXml(getXmlParser());
+ for (int i = 0; i < IfdId.TYPE_IFD_COUNT; i++) {
+ checkIfd(exifData.getIfdData(i), groundTruth.get(i));
+ }
+ checkThumbnail(exifData);
+ } catch (Exception e) {
+ throw new Exception(getImageTitle(), e);
}
- checkThumbnail(exifData);
}
private void checkThumbnail(ExifData exifData) {