summaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorEarl Ou <shunhsingou@google.com>2012-10-18 15:08:56 +0800
committerEarl Ou <shunhsingou@google.com>2012-10-18 15:12:20 +0800
commit3c9c7dc34721aaf7d83f037dd1af974bc064929f (patch)
treef4491ff1e388f952938d4701001fb2eb47c0bca8 /tests/src
parentb677dc86dd209b1a7632f934892a635d495d329d (diff)
downloadandroid_packages_apps_Snap-3c9c7dc34721aaf7d83f037dd1af974bc064929f.zip
android_packages_apps_Snap-3c9c7dc34721aaf7d83f037dd1af974bc064929f.tar.gz
android_packages_apps_Snap-3c9c7dc34721aaf7d83f037dd1af974bc064929f.tar.bz2
Handle duplicated tags in the Exif test
Change-Id: If9bd9712de1eaa71c8e355c5268f9cc29247bd2e
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/gallery3d/exif/ExifParserTest.java14
-rw-r--r--tests/src/com/android/gallery3d/exif/ExifReaderTest.java11
-rw-r--r--tests/src/com/android/gallery3d/exif/ExifXmlReader.java17
3 files changed, 27 insertions, 15 deletions
diff --git a/tests/src/com/android/gallery3d/exif/ExifParserTest.java b/tests/src/com/android/gallery3d/exif/ExifParserTest.java
index 38b1f2f..c93e09a 100644
--- a/tests/src/com/android/gallery3d/exif/ExifParserTest.java
+++ b/tests/src/com/android/gallery3d/exif/ExifParserTest.java
@@ -21,6 +21,7 @@ import android.graphics.BitmapFactory;
import java.util.List;
import java.util.Map;
+import java.util.Set;
public class ExifParserTest extends ExifXmlDataTestCase {
private static final String TAG = "ExifParserTest";
@@ -33,7 +34,7 @@ public class ExifParserTest extends ExifXmlDataTestCase {
super(imgPath, xmlPath);
}
- private List<Map<Short, String>> mGroundTruth;
+ private List<Map<Short, Set<String>>> mGroundTruth;
@Override
public void setUp() throws Exception {
@@ -83,20 +84,21 @@ 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());
+ Set<String> truth = mGroundTruth.get(tag.getIfd()).get(tag.getTagId());
- if (truthString == null) {
+ if (truth == null) {
fail(String.format("Unknown Tag %02x", tag.getTagId()) + ", " + getImageTitle());
}
String dataString = tag.valueToString().trim();
- assertEquals(String.format("Tag %02x", tag.getTagId()) + ", " + getImageTitle(),
- truthString.trim(), dataString);
+ assertTrue(String.format("Tag %02x", tag.getTagId()) + ", " + getImageTitle()
+ + ": " + dataString,
+ truth.contains(dataString));
}
private void parseOneIfd(int ifd, int options) throws Exception {
try {
- Map<Short, String> expectedResult = mGroundTruth.get(ifd);
+ Map<Short, Set<String>> expectedResult = mGroundTruth.get(ifd);
int numOfTag = 0;
ExifParser parser = ExifParser.parse(getImageInputStream(), options);
int event = parser.next();
diff --git a/tests/src/com/android/gallery3d/exif/ExifReaderTest.java b/tests/src/com/android/gallery3d/exif/ExifReaderTest.java
index 6a884ea..40d269e 100644
--- a/tests/src/com/android/gallery3d/exif/ExifReaderTest.java
+++ b/tests/src/com/android/gallery3d/exif/ExifReaderTest.java
@@ -20,6 +20,7 @@ import android.graphics.BitmapFactory;
import java.util.List;
import java.util.Map;
+import java.util.Set;
public class ExifReaderTest extends ExifXmlDataTestCase {
private static final String TAG = "ExifReaderTest";
@@ -36,7 +37,7 @@ public class ExifReaderTest extends ExifXmlDataTestCase {
try {
ExifReader reader = new ExifReader();
ExifData exifData = reader.read(getImageInputStream());
- List<Map<Short, String>> groundTruth = ExifXmlReader.readXml(getXmlParser());
+ List<Map<Short, Set<String>>> groundTruth = ExifXmlReader.readXml(getXmlParser());
for (int i = 0; i < IfdId.TYPE_IFD_COUNT; i++) {
checkIfd(exifData.getIfdData(i), groundTruth.get(i));
}
@@ -104,7 +105,7 @@ public class ExifReaderTest extends ExifXmlDataTestCase {
}
}
- private void checkIfd(IfdData ifd, Map<Short, String> ifdValue) {
+ private void checkIfd(IfdData ifd, Map<Short, Set<String>> ifdValue) {
if (ifd == null) {
assertEquals(getImageTitle(), 0 ,ifdValue.size());
return;
@@ -115,8 +116,10 @@ public class ExifReaderTest extends ExifXmlDataTestCase {
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());
+ Set<String> truth = ifdValue.get(tag.getTagId());
+ assertNotNull(String.format("Tag %x, ", tag.getTagId()) + getImageTitle(), truth);
+ assertTrue(String.format("Tag %x, ", tag.getTagId()) + getImageTitle(),
+ truth.contains(tag.valueToString().trim()));
}
size++;
}
diff --git a/tests/src/com/android/gallery3d/exif/ExifXmlReader.java b/tests/src/com/android/gallery3d/exif/ExifXmlReader.java
index 139b0ca..54def27 100644
--- a/tests/src/com/android/gallery3d/exif/ExifXmlReader.java
+++ b/tests/src/com/android/gallery3d/exif/ExifXmlReader.java
@@ -22,8 +22,10 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
public class ExifXmlReader {
private static final String TAG_EXIF = "exif";
@@ -44,13 +46,13 @@ public class ExifXmlReader {
* @throws XmlPullParserException
* @throws IOException
*/
- static public List<Map<Short, String>> readXml(XmlPullParser parser)
+ static public List<Map<Short, Set<String>>> readXml(XmlPullParser parser)
throws XmlPullParserException, IOException {
- List<Map<Short, String>> exifData =
- new ArrayList<Map<Short, String>>(IfdId.TYPE_IFD_COUNT);
+ List<Map<Short, Set<String>>> exifData =
+ new ArrayList<Map<Short, Set<String>>>(IfdId.TYPE_IFD_COUNT);
for (int i = 0; i < IfdId.TYPE_IFD_COUNT; i++) {
- exifData.add(new HashMap<Short, String>());
+ exifData.add(new HashMap<Short, Set<String>>());
}
while (parser.next() != XmlPullParser.END_DOCUMENT) {
@@ -79,7 +81,12 @@ public class ExifXmlReader {
if (ifdId < 0) {
// TODO: the MarkerNote segment.
} else {
- exifData.get(ifdId).put(id, value);
+ Set<String> tagData = exifData.get(ifdId).get(id);
+ if (tagData == null) {
+ tagData = new HashSet<String>();
+ exifData.get(ifdId).put(id, tagData);
+ }
+ tagData.add(value.trim());
}
parser.require(XmlPullParser.END_TAG, null, null);