summaryrefslogtreecommitdiffstats
path: root/tests/src/com
diff options
context:
space:
mode:
authorEarl Ou <shunhsingou@google.com>2012-10-17 13:57:23 +0800
committerEarl Ou <shunhsingou@google.com>2012-10-18 14:00:02 +0800
commitc1ceb80741fe7f50af4d03e6996d12b28220d090 (patch)
treeb19ca30e30d6f531bf467d6d07f901769824f322 /tests/src/com
parentcdd116de25c9a9cc14704cb7348077ed99c7ade9 (diff)
downloadandroid_packages_apps_Snap-c1ceb80741fe7f50af4d03e6996d12b28220d090.zip
android_packages_apps_Snap-c1ceb80741fe7f50af4d03e6996d12b28220d090.tar.gz
android_packages_apps_Snap-c1ceb80741fe7f50af4d03e6996d12b28220d090.tar.bz2
Make original exif test pass with the exiftool ground truth
Also add assertion message for debugging Change-Id: I4287afde01a2ad334b3d181d17863b1fa763950b
Diffstat (limited to 'tests/src/com')
-rw-r--r--tests/src/com/android/gallery3d/exif/ExifParserTest.java27
-rw-r--r--tests/src/com/android/gallery3d/exif/ExifReaderTest.java28
-rw-r--r--tests/src/com/android/gallery3d/exif/ExifXmlDataTestCase.java10
3 files changed, 45 insertions, 20 deletions
diff --git a/tests/src/com/android/gallery3d/exif/ExifParserTest.java b/tests/src/com/android/gallery3d/exif/ExifParserTest.java
index f89ac29..fccf261 100644
--- a/tests/src/com/android/gallery3d/exif/ExifParserTest.java
+++ b/tests/src/com/android/gallery3d/exif/ExifParserTest.java
@@ -76,14 +76,19 @@ public class ExifParserTest extends ExifXmlDataTestCase {
// We can verify it by examining the sub-IFD or thumbnail itself.
if (ExifTag.isSubIfdOffsetTag(tag.getTagId())) return;
- String truthString = mGroundTruth.get(tag.getIfd()).get(tag.getTagId());
+ // TODO: Test MakerNote and UserComment
+ if (tag.getTagId() == ExifTag.TAG_MAKER_NOTE
+ || tag.getTagId() == ExifTag.TAG_USER_COMMENT) return;
+
+ String truthString = mGroundTruth.get(tag.getIfd()).get(tag.getTagId()).trim();
if (truthString == null) {
- fail(String.format("Unknown Tag %02x", tag.getTagId()));
+ fail(String.format("Unknown Tag %02x", tag.getTagId()) + ", " + getImageTitle());
}
String dataString = tag.valueToString().trim();
- assertEquals(String.format("Tag %02x", tag.getTagId()), truthString, dataString);
+ assertEquals(String.format("Tag %02x", tag.getTagId()) + ", " + getImageTitle(),
+ truthString, dataString);
}
private void parseOneIfd(int ifd, int options)
@@ -95,11 +100,13 @@ public class ExifParserTest extends ExifXmlDataTestCase {
while(event != ExifParser.EVENT_END) {
switch (event) {
case ExifParser.EVENT_START_OF_IFD:
- assertEquals(ifd, parser.getCurrentIfd());
+ assertEquals(getImageTitle(), ifd, parser.getCurrentIfd());
break;
case ExifParser.EVENT_NEW_TAG:
ExifTag tag = parser.getTag();
- if (!ExifTag.isSubIfdOffsetTag(tag.getTagId())) numOfTag++;
+ // 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 {
@@ -117,7 +124,7 @@ public class ExifParserTest extends ExifXmlDataTestCase {
break;
case ExifParser.EVENT_COMPRESSED_IMAGE:
case ExifParser.EVENT_UNCOMPRESSED_STRIP:
- fail("Invalid Event type: " + event);
+ fail("Invalid Event type: " + event + ", " + getImageTitle());
break;
}
event = parser.next();
@@ -148,7 +155,7 @@ public class ExifParserTest extends ExifXmlDataTestCase {
while (event != ExifParser.EVENT_END) {
switch (event) {
case ExifParser.EVENT_START_OF_IFD:
- assertEquals(IfdId.TYPE_IFD_0, parser.getCurrentIfd());
+ assertEquals(getImageTitle(), IfdId.TYPE_IFD_0, parser.getCurrentIfd());
break;
case ExifParser.EVENT_NEW_TAG:
ExifTag tag = parser.getTag();
@@ -164,14 +171,14 @@ public class ExifParserTest extends ExifXmlDataTestCase {
break;
case ExifParser.EVENT_VALUE_OF_REGISTERED_TAG:
tag = parser.getTag();
- assertEquals(ExifTag.TAG_MODEL, tag.getTagId());
+ assertEquals(getImageTitle(), ExifTag.TAG_MODEL, tag.getTagId());
checkTag(tag);
isTagFound = true;
break;
}
event = parser.next();
}
- assertTrue(isTagFound);
+ assertTrue(getImageTitle(), isTagFound);
}
public void testReadThumbnail() throws Exception {
@@ -201,7 +208,7 @@ public class ExifParserTest extends ExifXmlDataTestCase {
event = parser.next();
}
if (mIsContainCompressedImage) {
- assertNotNull(bmp);
+ assertNotNull(getImageTitle(), bmp);
}
}
}
diff --git a/tests/src/com/android/gallery3d/exif/ExifReaderTest.java b/tests/src/com/android/gallery3d/exif/ExifReaderTest.java
index 3a78e09..c753df6 100644
--- a/tests/src/com/android/gallery3d/exif/ExifReaderTest.java
+++ b/tests/src/com/android/gallery3d/exif/ExifReaderTest.java
@@ -47,9 +47,10 @@ public class ExifReaderTest extends ExifXmlDataTestCase {
if (ifd1 != null) {
if (ifd1.getTag(ExifTag.TAG_COMPRESSION).getUnsignedShort(0) ==
ExifTag.Compression.JPEG) {
- assertTrue(exifData.hasCompressedThumbnail());
+ assertTrue(getImageTitle(), exifData.hasCompressedThumbnail());
byte[] thumbnail = exifData.getCompressedThumbnail();
- assertTrue(BitmapFactory.decodeByteArray(thumbnail, 0, thumbnail.length) != null);
+ assertTrue(getImageTitle(),
+ BitmapFactory.decodeByteArray(thumbnail, 0, thumbnail.length) != null);
} else {
// Try to check the strip count with the formula provided by EXIF spec.
int planarType = ExifTag.PlanarConfiguration.CHUNKY;
@@ -67,20 +68,23 @@ public class ExifReaderTest extends ExifXmlDataTestCase {
ExifTag.TAG_STRIP_OFFSETS).getComponentCount();
if (planarType == ExifTag.PlanarConfiguration.CHUNKY) {
- assertTrue(stripCount == (imageLength + rowsPerStrip - 1) / rowsPerStrip);
+ assertTrue(getImageTitle(),
+ stripCount == (imageLength + rowsPerStrip - 1) / rowsPerStrip);
} else {
ExifTag samplePerPixelTag = ifd1.getTag(ExifTag.TAG_SAMPLES_PER_PIXEL);
int samplePerPixel = samplePerPixelTag.getUnsignedShort(0);
- assertTrue(stripCount ==
+ assertTrue(getImageTitle(),
+ stripCount ==
(imageLength + rowsPerStrip - 1) / rowsPerStrip * samplePerPixel);
}
for (int i = 0; i < stripCount; i++) {
ExifTag byteCountTag = ifd1.getTag(ExifTag.TAG_STRIP_BYTE_COUNTS);
if (byteCountTag.getDataType() == ExifTag.TYPE_UNSIGNED_SHORT) {
- assertEquals(byteCountTag.getUnsignedShort(i), exifData.getStrip(i).length);
+ assertEquals(getImageTitle(),
+ byteCountTag.getUnsignedShort(i), exifData.getStrip(i).length);
} else {
- assertEquals(
+ assertEquals(getImageTitle(),
byteCountTag.getUnsignedLong(i), exifData.getStrip(i).length);
}
}
@@ -98,16 +102,20 @@ public class ExifReaderTest extends ExifXmlDataTestCase {
private void checkIfd(IfdData ifd, Map<Short, String> ifdValue) {
if (ifd == null) {
- assertEquals(0 ,ifdValue.size());
+ assertEquals(getImageTitle(), 0 ,ifdValue.size());
return;
}
ExifTag[] tags = ifd.getAllTags();
int size = 0;
for (ExifTag tag : tags) {
- if (ExifTag.isSubIfdOffsetTag(tag.getTagId())) continue;
- assertEquals(ifdValue.get(tag.getTagId()), tag.valueToString().trim());
+ if (ExifTag.isSubIfdOffsetTag(tag.getTagId())
+ || tag.getTagId() == ExifTag.TAG_MAKER_NOTE) continue;
+ if (tag.getTagId() != ExifTag.TAG_USER_COMMENT) {
+ assertEquals(String.format("Tag %x, ", tag.getTagId()) + getImageTitle(),
+ ifdValue.get(tag.getTagId()).trim(), tag.valueToString().trim());
+ }
size++;
}
- assertEquals(ifdValue.size(), size);
+ assertEquals(getImageTitle(), ifdValue.size(), size);
}
}
diff --git a/tests/src/com/android/gallery3d/exif/ExifXmlDataTestCase.java b/tests/src/com/android/gallery3d/exif/ExifXmlDataTestCase.java
index 16a7c68..5b61778 100644
--- a/tests/src/com/android/gallery3d/exif/ExifXmlDataTestCase.java
+++ b/tests/src/com/android/gallery3d/exif/ExifXmlDataTestCase.java
@@ -29,6 +29,8 @@ import java.io.InputStreamReader;
public class ExifXmlDataTestCase extends InstrumentationTestCase {
+ private static final String RES_ID_TITLE = "Resource ID: %x";
+
private InputStream mImageInputStream;
private InputStream mXmlInputStream;
private XmlPullParser mXmlParser;
@@ -78,4 +80,12 @@ public class ExifXmlDataTestCase extends InstrumentationTestCase {
Util.closeSilently(mImageInputStream);
Util.closeSilently(mXmlInputStream);
}
+
+ protected String getImageTitle() {
+ if (mImagePath != null) {
+ return mImagePath;
+ } else {
+ return String.format(RES_ID_TITLE, mImageResourceId);
+ }
+ }
}