summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/gallery3d/exif/ExifParserTest.java43
1 files changed, 35 insertions, 8 deletions
diff --git a/tests/src/com/android/gallery3d/exif/ExifParserTest.java b/tests/src/com/android/gallery3d/exif/ExifParserTest.java
index 34bbbda5f..8ae25e59a 100644
--- a/tests/src/com/android/gallery3d/exif/ExifParserTest.java
+++ b/tests/src/com/android/gallery3d/exif/ExifParserTest.java
@@ -131,6 +131,8 @@ public class ExifParserTest extends InstrumentationTestCase {
ExifInvalidFormatException {
int type = ifdParser.next();
int tagNumber=0;
+ boolean isEnterNextIfd = false;
+ boolean isEnterExifIfd = false;
while (type != IfdParser.TYPE_END) {
switch (type) {
case IfdParser.TYPE_NEW_TAG:
@@ -146,11 +148,13 @@ public class ExifParserTest extends InstrumentationTestCase {
break;
case IfdParser.TYPE_NEXT_IFD:
parseIfd1(ifdParser.parseIfdBlock());
+ isEnterNextIfd = true;
break;
case IfdParser.TYPE_VALUE_OF_PREV_TAG:
tag = ifdParser.getCorrespodingExifTag();
if(tag.getTagId() == ExifTag.TIFF_TAG.TAG_EXIF_IFD) {
parseExifIfd(ifdParser.parseIfdBlock());
+ isEnterExifIfd = true;
} else {
checkTag(ifdParser.getCorrespodingExifTag(), ifdParser, mIfd0Value);
tagNumber++;
@@ -160,6 +164,8 @@ public class ExifParserTest extends InstrumentationTestCase {
type = ifdParser.next();
}
assertEquals(mIfd0Value.size(), tagNumber);
+ assertTrue(isEnterNextIfd);
+ assertTrue(isEnterExifIfd);
}
private void parseIfd1(IfdParser ifdParser) throws IOException,
@@ -196,15 +202,21 @@ public class ExifParserTest extends InstrumentationTestCase {
ExifInvalidFormatException {
int type = ifdParser.next();
int tagNumber = 0;
+ boolean isHasInterIfd = false;
+ boolean isEnterInterIfd = false;
while (type != IfdParser.TYPE_END) {
switch (type) {
case IfdParser.TYPE_NEW_TAG:
ExifTag tag = ifdParser.readTag();
- if (tag.getDataSize() > 4
- || tag.getTagId() == ExifTag.EXIF_TAG.TAG_INTEROPERABILITY_IFD) {
+ if (tag.getDataSize() > 4) {
+ long offset = ifdParser.readUnsignedInt();
+ assertTrue(offset <= Integer.MAX_VALUE);
+ ifdParser.waitValueOfTag(tag, offset);
+ } else if (tag.getTagId() == ExifTag.EXIF_TAG.TAG_INTEROPERABILITY_IFD) {
long offset = ifdParser.readUnsignedInt();
assertTrue(offset <= Integer.MAX_VALUE);
ifdParser.waitValueOfTag(tag, offset);
+ isHasInterIfd = true;
} else {
checkTag(tag, ifdParser, mExifIfdValue);
tagNumber++;
@@ -217,6 +229,7 @@ public class ExifParserTest extends InstrumentationTestCase {
tag = ifdParser.getCorrespodingExifTag();
if (tag.getTagId() == ExifTag.EXIF_TAG.TAG_INTEROPERABILITY_IFD) {
parseInteroperabilityIfd(ifdParser.parseIfdBlock());
+ isEnterInterIfd = true;
} else {
checkTag(ifdParser.getCorrespodingExifTag(), ifdParser, mExifIfdValue);
tagNumber++;
@@ -226,6 +239,9 @@ public class ExifParserTest extends InstrumentationTestCase {
type = ifdParser.next();
}
assertEquals(mExifIfdValue.size(), tagNumber);
+ if (isHasInterIfd) {
+ assertTrue(isEnterInterIfd);
+ }
}
private void parseInteroperabilityIfd(IfdParser ifdParser) throws IOException,
ExifInvalidFormatException {
@@ -283,12 +299,8 @@ public class ExifParserTest extends InstrumentationTestCase {
}
break;
case ExifTag.TYPE_ASCII:
- buf = new byte[tag.getComponentCount()];
- parser.read(buf);
- int length = 0;
- while (buf[length] != 0 && length < buf.length) length++;
- // trim the string to fit the answer from xml
- sbuilder.append(new String(buf, 0, length).trim());
+ // trim the string for comparison between xml
+ sbuilder.append(parser.readString(tag.getComponentCount()).trim());
break;
case ExifTag.TYPE_INT:
for(int i = 0; i < tag.getComponentCount(); i++) {
@@ -338,6 +350,7 @@ public class ExifParserTest extends InstrumentationTestCase {
ExifParser exifParser = new ExifParser();
IfdParser ifdParser = exifParser.parse(mImageInputStream);
int type = ifdParser.next();
+ boolean isEnterNextIfd = false;
while (type != IfdParser.TYPE_END) {
switch (type) {
case IfdParser.TYPE_NEW_TAG:
@@ -345,6 +358,7 @@ public class ExifParserTest extends InstrumentationTestCase {
break;
case IfdParser.TYPE_NEXT_IFD:
parseIfd1(ifdParser.parseIfdBlock());
+ isEnterNextIfd = true;
break;
case IfdParser.TYPE_VALUE_OF_PREV_TAG:
// We won't get this since to skip everything
@@ -353,11 +367,14 @@ public class ExifParserTest extends InstrumentationTestCase {
}
type = ifdParser.next();
}
+ assertTrue(isEnterNextIfd);
}
public void testOnlySaveSomeValue() throws ExifInvalidFormatException, IOException {
ExifParser exifParser = new ExifParser();
IfdParser ifdParser = exifParser.parse(mImageInputStream);
+ boolean isEnterNextIfd = false;
+ boolean isEnterExifIfd = false;
int type = ifdParser.next();
while (type != IfdParser.TYPE_END) {
switch (type) {
@@ -375,11 +392,13 @@ public class ExifParserTest extends InstrumentationTestCase {
break;
case IfdParser.TYPE_NEXT_IFD:
parseIfd1(ifdParser.parseIfdBlock());
+ isEnterNextIfd = true;
break;
case IfdParser.TYPE_VALUE_OF_PREV_TAG:
tag = ifdParser.getCorrespodingExifTag();
if(tag.getTagId() == ExifTag.TIFF_TAG.TAG_EXIF_IFD) {
parseExifIfd(ifdParser.parseIfdBlock());
+ isEnterExifIfd = true;
} else {
checkTag(ifdParser.getCorrespodingExifTag(), ifdParser, mIfd0Value);
}
@@ -387,6 +406,8 @@ public class ExifParserTest extends InstrumentationTestCase {
}
type = ifdParser.next();
}
+ assertTrue(isEnterNextIfd);
+ assertTrue(isEnterExifIfd);
}
public void testReadThumbnail() throws ExifInvalidFormatException, IOException {
@@ -417,6 +438,12 @@ public class ExifParserTest extends InstrumentationTestCase {
long unsignedInt = ifdParser.readUnsignedInt();
assertTrue(unsignedInt <= Integer.MAX_VALUE);
thumbSize = (int) unsignedInt;
+ } else if (tag.getTagId() == ExifTag.TIFF_TAG.TAG_COMPRESSION) {
+ if (ifdParser.readUnsignedShort() ==
+ ExifTag.TIFF_TAG.COMPRESSION_UNCOMPRESSION) {
+ // This test doesn't apply to uncompression thumbnail.
+ return;
+ }
}
isFinishRead = thumbOffset != 0 && thumbSize != 0;
break;