You are viewing a plain text version of this content. The canonical link for it is here.
Posted to sanselan-commits@incubator.apache.org by cm...@apache.org on 2008/01/23 04:45:09 UTC

svn commit: r614420 [3/3] - in /incubator/sanselan/trunk/src: main/java/org/apache/sanselan/ main/java/org/apache/sanselan/common/ main/java/org/apache/sanselan/common/byteSources/ main/java/org/apache/sanselan/formats/bmp/ main/java/org/apache/sansela...

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifBaseTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifBaseTest.java?rev=614420&r1=614419&r2=614420&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifBaseTest.java (original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifBaseTest.java Tue Jan 22 20:44:55 2008
@@ -25,22 +25,23 @@
 import org.apache.sanselan.ImageReadException;
 import org.apache.sanselan.Sanselan;
 import org.apache.sanselan.SanselanTest;
-import org.apache.sanselan.formats.jpeg.JpegImageMetadata;
-import org.apache.sanselan.util.Debug;
+import org.apache.sanselan.common.byteSources.ByteSource;
+import org.apache.sanselan.common.byteSources.ByteSourceFile;
+import org.apache.sanselan.formats.jpeg.JpegImageParser;
 
 public abstract class ExifBaseTest extends SanselanTest
 {
-	public ExifBaseTest(String name)
-	{
-		super(name);
-	}
+	//	public ExifBaseTest(String name)
+	//	{
+	//		super(name);
+	//	}
 
 	protected static boolean hasExifData(File file) throws IOException,
 			ImageReadException
 	{
-//		Debug.debug("hasExifData file", file.getAbsoluteFile());
+		//		Debug.debug("hasExifData file", file.getAbsoluteFile());
 
-		if(!file.getName().toLowerCase().endsWith(".jpg"))
+		if (!file.getName().toLowerCase().endsWith(".jpg"))
 			return false;
 		ImageFormat format = Sanselan.guessFormat(file);
 		if (format != ImageFormat.IMAGE_FORMAT_JPEG)
@@ -50,20 +51,13 @@
 
 		try
 		{
-			JpegImageMetadata metadata = (JpegImageMetadata) Sanselan
-					.getMetadata(file);
-			if (null == metadata)
-				return false;
-
-			if (null == metadata.getExif())
-				return false;
-
-			return true;
+			ByteSource byteSource = new ByteSourceFile(file);
+			return new JpegImageParser().hasExifSegment(byteSource);
 		}
 		catch (Exception e)
 		{
-//			Debug.debug("Error file", file.getAbsoluteFile());
-//			Debug.debug(e, 4);
+			//			Debug.debug("Error file", file.getAbsoluteFile());
+			//			Debug.debug(e, 4);
 			return false;
 		}
 	}
@@ -82,6 +76,8 @@
 		return getTestImage(imageFilter);
 	}
 
+	//	, int max
+	//	
 	protected List getImagesWithExifData() throws IOException,
 			ImageReadException
 	{

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifDumpTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifDumpTest.java?rev=614420&r1=614419&r2=614420&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifDumpTest.java (original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifDumpTest.java Tue Jan 22 20:44:55 2008
@@ -19,7 +19,9 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.sanselan.ImageReadException;
 import org.apache.sanselan.ImageWriteException;
@@ -32,17 +34,19 @@
 
 public class ExifDumpTest extends ExifBaseTest
 {
-	public ExifDumpTest(String name)
-	{
-		super(name);
-	}
+//	public ExifDumpTest(String name)
+//	{
+//		super(name);
+//	}
 
-	public void testRemove() throws IOException, ImageReadException,
+	public void test() throws IOException, ImageReadException,
 			ImageWriteException
 	{
 		List images = getImagesWithExifData();
 		for (int i = 0; i < images.size(); i++)
 		{
+			Debug.purgeMemory();
+
 			File imageFile = (File) images.get(i);
 			Debug.debug("imageFile", imageFile);
 			Debug.debug();
@@ -51,9 +55,15 @@
 			Debug.debug("Segments:");
 			new JpegUtils().dumpJFIF(byteSource);
 
+			Map params = new HashMap();
+			boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+			params.put(PARAM_KEY_READ_THUMBNAILS, new Boolean(!ignoreImageData));
+
 			JpegImageMetadata metadata = (JpegImageMetadata) Sanselan
-					.getMetadata(imageFile);
-			assertNotNull(metadata.getExif());
+					.getMetadata(imageFile, params);
+			if(null==metadata)
+				continue;
+//			assertNotNull(metadata.getExif());
 
 			metadata.dump();
 		}

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java?rev=614420&r1=614419&r2=614420&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java (original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java Tue Jan 22 20:44:55 2008
@@ -23,8 +23,10 @@
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.sanselan.ImageReadException;
 import org.apache.sanselan.ImageWriteException;
@@ -42,13 +44,12 @@
 import org.apache.sanselan.util.Debug;
 import org.apache.sanselan.util.IOUtils;
 
-
 public class ExifRewriteTest extends ExifBaseTest implements AllTagConstants
 {
-	public ExifRewriteTest(String name)
-	{
-		super(name);
-	}
+	//	public ExifRewriteTest(String name)
+	//	{
+	//		super(name);
+	//	}
 
 	public void testRemove() throws IOException, ImageReadException,
 			ImageWriteException
@@ -56,9 +57,15 @@
 		List images = getImagesWithExifData();
 		for (int i = 0; i < images.size(); i++)
 		{
+			Debug.purgeMemory();
+
 			File imageFile = (File) images.get(i);
 			Debug.debug("imageFile", imageFile);
 
+			boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+			if (ignoreImageData)
+				continue;
+
 			ByteSource byteSource = new ByteSourceFile(imageFile);
 			Debug.debug("Source Segments:");
 			new JpegUtils().dumpJFIF(byteSource);
@@ -66,7 +73,7 @@
 			{
 				JpegImageMetadata metadata = (JpegImageMetadata) Sanselan
 						.getMetadata(imageFile);
-				assertNotNull(metadata.getExif());
+				//				assertNotNull(metadata.getExif());
 			}
 
 			{
@@ -86,6 +93,82 @@
 		}
 	}
 
+	public void testInsert() throws IOException, ImageReadException,
+			ImageWriteException
+	{
+		List images = getImagesWithExifData();
+		for (int i = 0; i < images.size(); i++)
+		{
+			Debug.purgeMemory();
+
+			File imageFile = (File) images.get(i);
+			Debug.debug("imageFile", imageFile);
+
+			boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+			if (ignoreImageData)
+				continue;
+
+			ByteSource byteSource = new ByteSourceFile(imageFile);
+			Debug.debug("Source Segments:");
+			new JpegUtils().dumpJFIF(byteSource);
+
+			JpegImageMetadata originalMetadata = (JpegImageMetadata) Sanselan
+					.getMetadata(imageFile);
+			assertNotNull(originalMetadata);
+
+			TiffImageMetadata oldExifMetadata = originalMetadata.getExif();
+			assertNotNull(oldExifMetadata);
+
+			ByteSource stripped;
+			{
+				ByteArrayOutputStream baos = new ByteArrayOutputStream();
+				new ExifRewriter().removeExifMetadata(byteSource, baos);
+				byte bytes[] = baos.toByteArray();
+				File tempFile = File.createTempFile("removed", ".jpg");
+				Debug.debug("tempFile", tempFile);
+				tempFile.deleteOnExit();
+				IOUtils.writeToFile(bytes, tempFile);
+
+				Debug.debug("Output Segments:");
+				stripped = new ByteSourceArray(bytes);
+				new JpegUtils().dumpJFIF(stripped);
+
+				assertTrue(!hasExifData(tempFile));
+			}
+
+			{
+				TiffOutputSet outputSet = oldExifMetadata.getOutputSet();
+				//			outputSet.dump();
+
+				ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+				new ExifRewriter().updateExifMetadataLossy(stripped, baos,
+						outputSet);
+
+				byte bytes[] = baos.toByteArray();
+				File tempFile = File.createTempFile("inserted" + "_", ".jpg");
+				Debug.debug("tempFile", tempFile);
+				//			tempFile.deleteOnExit();
+				IOUtils.writeToFile(bytes, tempFile);
+
+				Debug.debug("Output Segments:");
+				new JpegUtils().dumpJFIF(new ByteSourceArray(bytes));
+
+				//				assertTrue(!hasExifData(tempFile));
+
+				JpegImageMetadata newMetadata = (JpegImageMetadata) Sanselan
+						.getMetadata(tempFile);
+				assertNotNull(newMetadata);
+				TiffImageMetadata newExifMetadata = newMetadata.getExif();
+				assertNotNull(newExifMetadata);
+				//				newMetadata.dump();
+
+				compare(oldExifMetadata, newExifMetadata);
+			}
+
+		}
+	}
+
 	private interface Rewriter
 	{
 		public void rewrite(ByteSource byteSource, OutputStream os,
@@ -93,54 +176,88 @@
 				IOException, ImageWriteException;
 	}
 
-	public void rewrite(Rewriter rewriter, String name) throws IOException,
+	private void rewrite(Rewriter rewriter, String name) throws IOException,
 			ImageReadException, ImageWriteException
 	{
 		List images = getImagesWithExifData();
 		for (int i = 0; i < images.size(); i++)
 		{
+			Debug.purgeMemory();
+
 			File imageFile = (File) images.get(i);
-			Debug.debug("imageFile", imageFile);
 
-			ByteSource byteSource = new ByteSourceFile(imageFile);
-			Debug.debug("Source Segments:");
-			new JpegUtils().dumpJFIF(byteSource);
+			try
+			{
 
-			JpegImageMetadata oldMetadata = (JpegImageMetadata) Sanselan
-					.getMetadata(imageFile);
-			assertNotNull(oldMetadata);
+				Debug.debug("imageFile", imageFile);
 
-			TiffImageMetadata oldExifMetadata = oldMetadata.getExif();
-			assertNotNull(oldExifMetadata);
-			oldMetadata.dump();
+				boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+				if (ignoreImageData)
+					continue;
+
+				ByteSource byteSource = new ByteSourceFile(imageFile);
+				Debug.debug("Source Segments:");
+				new JpegUtils().dumpJFIF(byteSource);
+
+				JpegImageMetadata oldMetadata = (JpegImageMetadata) Sanselan
+						.getMetadata(imageFile);
+				if (null == oldMetadata)
+					continue;
+				assertNotNull(oldMetadata);
+
+				TiffImageMetadata oldExifMetadata = oldMetadata.getExif();
+				if (null == oldExifMetadata)
+					continue;
+				assertNotNull(oldExifMetadata);
+				oldMetadata.dump();
+
+				//			TiffImageMetadata tiffImageMetadata = metadata.getExif();
+				//			Photoshop photoshop = metadata.getPhotoshop();
+
+				TiffOutputSet outputSet = oldExifMetadata.getOutputSet();
+				//			outputSet.dump();
+
+				ByteArrayOutputStream baos = new ByteArrayOutputStream();
+				rewriter.rewrite(byteSource, baos, outputSet);
+				byte bytes[] = baos.toByteArray();
+				File tempFile = File.createTempFile(name + "_", ".jpg");
+				Debug.debug("tempFile", tempFile);
+				//			tempFile.deleteOnExit();
+				IOUtils.writeToFile(bytes, tempFile);
+
+				Debug.debug("Output Segments:");
+				new JpegUtils().dumpJFIF(new ByteSourceArray(bytes));
 
-			//			TiffImageMetadata tiffImageMetadata = metadata.getExif();
-			//			Photoshop photoshop = metadata.getPhotoshop();
+				//				assertTrue(!hasExifData(tempFile));
 
-			TiffOutputSet outputSet = oldExifMetadata.getOutputSet();
-			//			outputSet.dump();
+				JpegImageMetadata newMetadata = (JpegImageMetadata) Sanselan
+						.getMetadata(tempFile);
+				assertNotNull(newMetadata);
+				TiffImageMetadata newExifMetadata = newMetadata.getExif();
+				assertNotNull(newExifMetadata);
+				//				newMetadata.dump();
 
-			ByteArrayOutputStream baos = new ByteArrayOutputStream();
-			rewriter.rewrite(byteSource, baos, outputSet);
-			byte bytes[] = baos.toByteArray();
-			File tempFile = File.createTempFile(name + "_", ".jpg");
-			Debug.debug("tempFile", tempFile);
-//			tempFile.deleteOnExit();
-			IOUtils.writeToFile(bytes, tempFile);
-
-			Debug.debug("Output Segments:");
-			new JpegUtils().dumpJFIF(new ByteSourceArray(bytes));
-
-			//				assertTrue(!hasExifData(tempFile));
-
-			JpegImageMetadata newMetadata = (JpegImageMetadata) Sanselan
-					.getMetadata(tempFile);
-			assertNotNull(newMetadata);
-			TiffImageMetadata newExifMetadata = newMetadata.getExif();
-			assertNotNull(newExifMetadata);
-			//			newMetadata.dump();
+				compare(oldExifMetadata, newExifMetadata);
+			}
+			catch (IOException e)
+			{
+				Debug.debug("imageFile", imageFile.getAbsoluteFile());
+				Debug.debug(e);
+				throw e;
+			}
+			catch (ImageReadException e)
+			{
+				Debug.debug("imageFile", imageFile.getAbsoluteFile());
+				Debug.debug(e);
+				throw e;
+			}
+			catch (ImageWriteException e)
+			{
+				Debug.debug("imageFile", imageFile.getAbsoluteFile());
+				Debug.debug(e);
+				throw e;
+			}
 
-			compare(oldExifMetadata, newExifMetadata);
 		}
 	}
 
@@ -197,13 +314,15 @@
 		{
 			TiffImageMetadata.Item item = (TiffImageMetadata.Item) items.get(i);
 			TiffField field = item.getTiffField();
-			fieldMap.put(new Integer(field.tag), field);
+			Object key = new Integer(field.tag);
+			if (!fieldMap.containsKey(key))
+				fieldMap.put(key, field);
 		}
 		return fieldMap;
 	}
 
 	private void compare(TiffImageMetadata oldExifMetadata,
-			TiffImageMetadata newExifMetadata)
+			TiffImageMetadata newExifMetadata) throws ImageReadException
 	{
 		assertNotNull(oldExifMetadata);
 		assertNotNull(newExifMetadata);
@@ -244,15 +363,35 @@
 			//			dump("oldItems", oldItems);
 			//			dump("newItems", newItems);
 
-			assertTrue(oldItems.size() == newItems.size());
+			//			if (oldItems.size() != newItems.size())
+			//				;
+			//			{
+			//			dump("oldItems", oldItems);
+			//			dump("newItems", newItems);
+			//			}
+			//			assertTrue(oldItems.size() == newItems.size());
 
 			Hashtable oldFieldMap = makeFieldMap(oldItems);
 			Hashtable newFieldMap = makeFieldMap(newItems);
 
+			Set missingInNew = new HashSet(oldFieldMap.keySet());
+			missingInNew.removeAll(newFieldMap.keySet());
+
+			Set missingInOld = new HashSet(newFieldMap.keySet());
+			missingInOld.removeAll(oldFieldMap.keySet());
+
+			//			dump("missingInNew", missingInNew);
+			//			dump("missingInOld", missingInOld);
+			//			dump("newFieldMap.keySet()", newFieldMap.keySet());
+			//			dump("oldFieldMap.keySet()", oldFieldMap.keySet());
+
+			assertTrue(missingInNew.size() == 0);
+			assertTrue(missingInOld.size() == 0);
+
 			//			Debug.debug("oldItems.size()", oldItems.size());
 			//			Debug.debug("oldFieldMap.keySet().size()", oldFieldMap.keySet().size());
 
-			assertEquals(oldItems.size(), oldFieldMap.keySet().size());
+			//			assertEquals(oldItems.size(), oldFieldMap.keySet().size());
 			//			assertEquals(oldFieldMap.keySet(), newFieldMap.keySet());
 			//			assertEquals(oldFieldMap.keySet(), newFieldMap.keySet());
 
@@ -271,7 +410,7 @@
 
 				//				Debug.debug("fieldTag", fieldTag);
 				//				Debug.debug("oldField", oldField);
-				//				Debug.debug("fieldTag", fieldTag);
+				//				Debug.debug("newField", newField);
 
 				//				fieldTag.
 				assertNotNull(oldField);
@@ -283,15 +422,56 @@
 				assertEquals(oldField.length, newField.length);
 				assertEquals(oldField.isLocalValue(), newField.isLocalValue());
 
+				if (oldField.tag == 0x202)
+				{
+					// ignore "jpg from raw length" value. may have off-by-one bug in certain cameras.
+					// i.e. Sony DCR-PC110
+					continue;
+				}
+
 				if (!oldField.tagInfo.isOffset())
 				{
-					if (oldField.isLocalValue())
+					if (oldField.tagInfo.isText())
+						;
+					else if (oldField.isLocalValue())
 					{
-						compare(oldField.valueOffsetBytes,
-								newField.valueOffsetBytes);
+						//						Debug.debug("oldField.tag", oldField.tag);
+						//						Debug.debug("newField.tag", newField.tag);
+						//						Debug.debug("oldField.tagInfo", oldField.tagInfo);
+						//						Debug.debug("newField.tagInfo", newField.tagInfo);
+						//						Debug.debug("oldField.fieldType", oldField.fieldType);
+						//						Debug.debug("newField.fieldType", newField.fieldType);
+						//						Debug.debug("oldField.getBytesLength", oldField
+						//								.getBytesLength());
+						//						Debug.debug("newField.getBytesLength", newField
+						//								.getBytesLength());
+						//
+						//						Debug.debug("oldField.valueOffsetBytes",
+						//								oldField.valueOffsetBytes);
+						//						Debug.debug("newField.valueOffsetBytes",
+						//								newField.valueOffsetBytes);
+
+						if (oldField.tag == 0x116 || oldField.tag == 0x117)
+							compare(oldField, newField);
+						else
+							compare(oldField.valueOffsetBytes,
+									newField.valueOffsetBytes, oldField
+											.getBytesLength(), newField
+											.getBytesLength());
 					}
 					else
 					{
+						//						Debug.debug("oldField.tagInfo", oldField.tagInfo);
+						//						Debug.debug("oldField.fieldType", oldField.fieldType);
+						//						Debug.debug("newField.fieldType", newField.fieldType);
+						//						Debug.debug("oldField.getBytesLength", oldField
+						//								.getBytesLength());
+						//						Debug.debug("newField.getBytesLength", newField
+						//								.getBytesLength());
+
+						//						Debug.debug("oldField.oversizeValue", oldField.oversizeValue);
+						//						Debug.debug("newField.oversizeValue", newField.oversizeValue);
+
 						compare(oldField.oversizeValue, newField.oversizeValue);
 					}
 				}
@@ -302,13 +482,62 @@
 		}
 	}
 
+	private void compare(byte a[], byte b[], int aLength, int bLength)
+	{
+		//		Debug.debug("c0 a", a);
+		//		Debug.debug("c0 b", b);
+		assertEquals(aLength, bLength);
+		assertTrue(a.length >= aLength);
+		assertTrue(b.length >= bLength);
+		assertNotNull(a);
+		assertNotNull(b);
+		assertEquals(a.length, b.length);
+		int length = aLength;
+		for (int i = 0; i < length; i++)
+		{
+			//			byte ba = a[i];
+			//			byte bb = b[i];
+			//			boolean eq = ba == bb;
+			//			Debug.debug("i: " + i + ", a[i]: " + ba + ", b[i]: " + bb + " = "
+			//					+ (ba == bb) + " " + eq);
+			//			if(ba != bb)
+			//				assertFalse(true);
+			//			
+			//			Debug.debug("i: " + i + ", a[i]: " + ba + ", b[i]: " + bb + " = "
+			//					+ (ba == bb) + " " + eq);
+			//			assertTrue(eq == true);
+			//			Debug.debug("a", a);
+			//			Debug.debug("b", b);
+			assertTrue(a[i] == b[i]);
+			//			Debug.debug("c");
+			//			assertTrue((0xff & a[i]) == (0xff & b[i]));
+		}
+	}
+
+	private void compare(TiffField a, TiffField b) throws ImageReadException
+	{
+		Object v1 = a.getValue();
+		Object v2 = b.getValue();
+
+		//		Debug.debug("v1", v1 + " (" + Debug.getType(v1) + ")");
+		//		Debug.debug("v2", v2 + " (" + Debug.getType(v2) + ")");
+		assertTrue(v1.equals(v2));
+	}
+
 	private void compare(byte a[], byte b[])
 	{
+		//		Debug.debug("c1 a", a);
+		//		Debug.debug("c1 b", b);
 		assertNotNull(a);
 		assertNotNull(b);
 		assertEquals(a.length, b.length);
 		for (int i = 0; i < a.length; i++)
 			assertEquals(a[i], b[i]);
+	}
+
+	private void dump(String name, Set set)
+	{
+		dump(name, new ArrayList(set));
 	}
 
 	private void dump(String name, List list)

Added: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/GpsTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/GpsTest.java?rev=614420&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/GpsTest.java (added)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/GpsTest.java Tue Jan 22 20:44:55 2008
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.sanselan.formats.jpeg.exif;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.sanselan.Sanselan;
+import org.apache.sanselan.SanselanConstants;
+import org.apache.sanselan.formats.jpeg.JpegImageMetadata;
+import org.apache.sanselan.formats.tiff.TiffImageMetadata;
+import org.apache.sanselan.util.Debug;
+
+public class GpsTest extends ExifBaseTest implements SanselanConstants
+{
+
+	public void test() throws Exception
+
+	{
+
+		List images = getImagesWithExifData();
+		for (int i = 0; i < images.size(); i++)
+		{
+			Debug.purgeMemory();
+
+			File imageFile = (File) images.get(i);
+			if (imageFile.getParentFile().getName().toLowerCase().equals(
+					"@broken"))
+				continue;
+
+			try
+			{
+				Map params = new HashMap();
+				boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+				params.put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
+						!ignoreImageData));
+
+				JpegImageMetadata metadata = (JpegImageMetadata) Sanselan
+						.getMetadata(imageFile, params);
+				if (null == metadata)
+					continue;
+
+				TiffImageMetadata exifMetadata = metadata.getExif();
+				if (null == exifMetadata)
+					continue;
+
+				TiffImageMetadata.GPSInfo gpsInfo = exifMetadata.getGPS();
+				if (null == gpsInfo)
+					continue;
+
+				Debug.debug("imageFile", imageFile);
+				Debug.debug("gpsInfo", gpsInfo);
+				Debug.debug();
+			}
+			catch (Exception e)
+			{
+				Debug.debug("imageFile", imageFile.getAbsoluteFile());
+				Debug.debug("imageFile", imageFile.length());
+				Debug.debug(e, 13);
+
+				//				File brokenFolder = new File(imageFile.getParentFile(), "@Broken");
+				//				if(!brokenFolder.exists())
+				//					brokenFolder.mkdirs();
+				//				File movedFile = new File(brokenFolder, imageFile.getName());
+				//				imageFile.renameTo(movedFile);
+
+				throw e;
+			}
+		}
+
+	}
+}

Propchange: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/GpsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java?rev=614420&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java (added)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java Tue Jan 22 20:44:55 2008
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.sanselan.formats.jpeg.exif;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.ImageWriteException;
+import org.apache.sanselan.formats.tiff.TiffField;
+import org.apache.sanselan.util.Debug;
+
+public class MakerNoteFieldTest extends SpecificExifTagTest
+{
+	//	public MakerNoteFieldTest(String name)
+	//	{
+	//		super(name);
+	//	}
+
+	protected void checkField(File imageFile, TiffField field)
+			throws IOException, ImageReadException, ImageWriteException
+	{
+		if (field.tag == EXIF_TAG_MAKER_NOTE.tag)
+			;
+		else
+			//			if (field.tag == EXIF_TAG_EXIF_OFFSET.tag)
+			//				;
+			//			else
+			return;
+
+		Debug.debug("imageFile", imageFile);
+		Debug.debug("field", field);
+		Debug.debug("field", Debug.getType(field));
+
+		Debug.debug("field", field.tag);
+		Debug.debug("field", field.tagInfo);
+		Debug.debug("length", field.length);
+		Debug.debug("fieldType", field.fieldType);
+		//				Debug.debug("field", Debug.getType(field));
+		Debug.debug();
+
+		//		try
+		//		{
+		//			Object userCommentValue = field.getValue();
+		//			Debug.debug("Text field value(" + field.tagInfo.name + ")",
+		//					userCommentValue);
+		//			//		Debug.debug("userCommentValue", Debug.getType(userCommentValue));
+		//		}
+		//		catch (ImageReadException e)
+		//		{
+		//			Debug.debug("imageFile", imageFile);
+		//			Debug.debug(e);
+		//		}
+
+	}
+
+}

Propchange: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/SpecificExifTagTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/SpecificExifTagTest.java?rev=614420&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/SpecificExifTagTest.java (added)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/SpecificExifTagTest.java Tue Jan 22 20:44:55 2008
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.sanselan.formats.jpeg.exif;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.ImageWriteException;
+import org.apache.sanselan.Sanselan;
+import org.apache.sanselan.common.IImageMetadata;
+import org.apache.sanselan.formats.jpeg.JpegImageMetadata;
+import org.apache.sanselan.formats.tiff.TiffField;
+import org.apache.sanselan.formats.tiff.TiffImageMetadata;
+import org.apache.sanselan.formats.tiff.constants.AllTagConstants;
+import org.apache.sanselan.util.Debug;
+
+public abstract class SpecificExifTagTest extends ExifBaseTest
+		implements
+			AllTagConstants
+{
+//	public SpecificExifTagTest(String name)
+//	{
+//		super(name);
+//	}
+
+	public void testSingleImage() throws IOException, ImageReadException,
+			ImageWriteException
+	{
+		File imageFile = getImageWithExifData();
+		checkImage(imageFile);
+	}
+
+	public void testAllImages() throws IOException, ImageReadException,
+			ImageWriteException
+	{
+		List images = getImagesWithExifData();
+		for (int i = 0; i < images.size(); i++)
+		{
+			Debug.purgeMemory();
+
+			File imageFile = (File) images.get(i);
+			if (imageFile.getParentFile().getName().toLowerCase().equals("@broken"))
+				continue;
+			checkImage(imageFile);
+		}
+	}
+
+	protected abstract void checkField(File imageFile, TiffField field)
+			throws IOException, ImageReadException, ImageWriteException;
+
+	private void checkImage(File imageFile) throws IOException,
+			ImageReadException, ImageWriteException
+	{
+//		Debug.debug("imageFile", imageFile.getAbsoluteFile());
+
+		Map params = new HashMap();
+		boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+		params.put(PARAM_KEY_READ_THUMBNAILS, new Boolean(!ignoreImageData));
+
+		// note that metadata might be null if no metadata is found.
+		IImageMetadata metadata = Sanselan.getMetadata(imageFile, params);
+		if (null == metadata)
+			return;
+		JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
+
+		// note that exif might be null if no Exif metadata is found.
+		TiffImageMetadata exif = jpegMetadata.getExif();
+		if (null == exif)
+			return;
+
+		List fields = exif.getAllFields();
+		for (int i = 0; i < fields.size(); i++)
+		{
+			TiffField field = (TiffField) fields.get(i);
+			checkField(imageFile, field);
+		}
+
+	}
+
+}

Propchange: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/SpecificExifTagTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/TextFieldTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/TextFieldTest.java?rev=614420&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/TextFieldTest.java (added)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/TextFieldTest.java Tue Jan 22 20:44:55 2008
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.sanselan.formats.jpeg.exif;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.ImageWriteException;
+import org.apache.sanselan.formats.tiff.TiffField;
+import org.apache.sanselan.util.Debug;
+
+public class TextFieldTest extends SpecificExifTagTest
+{
+	//	public TextFieldTest(String name)
+	//	{
+	//		super(name);
+	//	}
+
+	protected void checkField(File imageFile, TiffField field)
+			throws IOException, ImageReadException, ImageWriteException
+	{
+		if (field.tag == EXIF_TAG_USER_COMMENT.tag)
+			;
+		else if (field.tag == GPS_TAG_GPS_PROCESSING_METHOD.tag
+				&& field.directoryType == EXIF_DIRECTORY_GPS.directoryType)
+			;
+		else if (field.tag == GPS_TAG_GPS_AREA_INFORMATION.tag
+				&& field.directoryType == EXIF_DIRECTORY_GPS.directoryType)
+			;
+		else
+			return;
+
+		//		Debug.debug("field", field);
+		//		Debug.debug("field", Debug.getType(field));
+		//
+		//		Debug.debug("field", field.tag);
+		//		Debug.debug("field", field.tagInfo);
+		//		Debug.debug("field", Debug.getType(field));
+
+		try
+		{
+			Object textFieldValue = field.getValue();
+			//			Debug.debug("imageFile", imageFile.getAbsoluteFile());
+			//			Debug.debug("Text field value(" + field.tagInfo.name + ")",
+			//					textFieldValue);
+			//		Debug.debug("userCommentValue", Debug.getType(userCommentValue));
+		}
+		catch (ImageReadException e)
+		{
+			Debug.debug("imageFile", imageFile.getAbsoluteFile());
+			Debug.debug(e);
+			throw e;
+		}
+
+	}
+
+}

Propchange: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/TextFieldTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java?rev=614420&r1=614419&r2=614420&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java (original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java Tue Jan 22 20:44:55 2008
@@ -32,10 +32,10 @@
 		implements
 			AllTagConstants
 {
-	public WriteExifMetadataExampleTest(String name)
-	{
-		super(name);
-	}
+//	public WriteExifMetadataExampleTest(String name)
+//	{
+//		super(name);
+//	}
 
 	public void test() throws IOException, ImageReadException,
 			ImageWriteException
@@ -43,6 +43,8 @@
 		List images = getImagesWithExifData();
 		for (int i = 0; i < images.size(); i++)
 		{
+			Debug.purgeMemory();
+			
 			File imageFile = (File) images.get(i);
 			Debug.debug("imageFile", imageFile.getAbsoluteFile());
 
@@ -52,6 +54,9 @@
 
 			try
 			{
+				boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+				if(ignoreImageData)
+					continue;
 				new WriteExifMetadataExample().changeExifMetadata(imageFile,
 						tempFile);
 			}

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngReadTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngReadTest.java?rev=614420&r1=614419&r2=614420&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngReadTest.java (original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngReadTest.java Tue Jan 22 20:44:55 2008
@@ -33,10 +33,10 @@
 
 public class PngReadTest extends SanselanTest
 {
-	public PngReadTest(String name)
-	{
-		super(name);
-	}
+//	public PngReadTest(String name)
+//	{
+//		super(name);
+//	}
 
 	private static boolean isPng(File file) throws IOException,
 			ImageReadException
@@ -53,10 +53,10 @@
 		}
 	};
 
-	private File getPngImage() throws IOException, ImageReadException
-	{
-		return getTestImage(imageFilter);
-	}
+//	private File getPngImage() throws IOException, ImageReadException
+//	{
+//		return getTestImage(imageFilter);
+//	}
 
 	private List getPngImages() throws IOException, ImageReadException
 	{
@@ -71,6 +71,8 @@
 		List images = getPngImages();
 		for (int i = 0; i < images.size(); i++)
 		{
+			Debug.purgeMemory();
+
 			File imageFile = (File) images.get(i);
 			Debug.debug("imageFile", imageFile);
 			if (imageFile.getParentFile().getName()

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngWriteReadTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngWriteReadTest.java?rev=614420&r1=614419&r2=614420&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngWriteReadTest.java (original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngWriteReadTest.java Tue Jan 22 20:44:55 2008
@@ -33,10 +33,10 @@
 
 public class PngWriteReadTest extends SanselanTest
 {
-	public PngWriteReadTest(String name)
-	{
-		super(name);
-	}
+	//	public PngWriteReadTest(String name)
+	//	{
+	//		super(name);
+	//	}
 
 	private int[][] getSimpleRawData(int width, int height, int value)
 	{
@@ -143,6 +143,7 @@
 
 		File tmpDirectory = new File("tmp");
 		File tempFile = File.createTempFile("temp", ".png", tmpDirectory);
+		tempFile.deleteOnExit();
 		IOUtils.writeToFile(bytes, tempFile);
 
 		BufferedImage dstImage = Sanselan.getBufferedImage(bytes);

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/tiff/TiffReadTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/tiff/TiffReadTest.java?rev=614420&r1=614419&r2=614420&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/tiff/TiffReadTest.java (original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/tiff/TiffReadTest.java Tue Jan 22 20:44:55 2008
@@ -33,10 +33,10 @@
 
 public class TiffReadTest extends SanselanTest
 {
-	public TiffReadTest(String name)
-	{
-		super(name);
-	}
+//	public TiffReadTest(String name)
+//	{
+//		super(name);
+//	}
 
 	private static boolean isTiff(File file) throws IOException,
 			ImageReadException
@@ -53,10 +53,10 @@
 		}
 	};
 
-	private File getTiffImage() throws IOException, ImageReadException
-	{
-		return getTestImage(imageFilter);
-	}
+//	private File getTiffImage() throws IOException, ImageReadException
+//	{
+//		return getTestImage(imageFilter);
+//	}
 
 	private List getTiffImages() throws IOException, ImageReadException
 	{
@@ -69,6 +69,8 @@
 		List images = getTiffImages();
 		for (int i = 0; i < images.size(); i++)
 		{
+			Debug.purgeMemory();
+
 			File imageFile = (File) images.get(i);
 			Debug.debug("imageFile", imageFile);