commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r995634 [3/6] - in /commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan: ./ common/ common/byteSources/ formats/bmp/ formats/gif/ formats/ico/ formats/jpeg/ formats/jpeg/exif/ formats/jpeg/iptc/ formats/jpeg/xmp/ formats/png/ fo...
Date Fri, 10 Sep 2010 01:35:52 GMT
Modified: commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java?rev=995634&r1=995633&r2=995634&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java (original)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java Fri Sep 10 01:35:50 2010
@@ -46,500 +46,500 @@ import org.apache.sanselan.util.IOUtils;
 
 public class ExifRewriteTest extends ExifBaseTest implements AllTagConstants
 {
-	//	public ExifRewriteTest(String name)
-	//	{
-	//		super(name);
-	//	}
-
-	public void testRemove() throws IOException, ImageReadException,
-			ImageWriteException
-	{
-		List images = getImagesWithExifData();
-		for (int i = 0; i < images.size(); i++)
-		{
-			if(i%10==0)
-			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 metadata = (JpegImageMetadata) Sanselan
-						.getMetadata(imageFile);
-				//				assertNotNull(metadata.getExif());
-			}
-
-			{
-				ByteArrayOutputStream baos = new ByteArrayOutputStream();
-				new ExifRewriter().removeExifMetadata(byteSource, baos);
-				byte bytes[] = baos.toByteArray();
-				File tempFile = createTempFile("test", ".jpg");
-				Debug.debug("tempFile", tempFile);
-				IOUtils.writeToFile(bytes, tempFile);
-
-				Debug.debug("Output Segments:");
-				new JpegUtils().dumpJFIF(new ByteSourceArray(bytes));
-
-				assertTrue(!hasExifData(tempFile));
-			}
-		}
-	}
-
-	public void testInsert() throws IOException, ImageReadException,
-			ImageWriteException
-	{
-		List images = getImagesWithExifData();
-		for (int i = 0; i < images.size(); i++)
-		{
-			if(i%10==0)
-			Debug.purgeMemory();
-
-			File imageFile = (File) images.get(i);
-			Debug.debug("imageFile", imageFile);
-			
-			// This test image contains invalid EXIF and would break the test.
-			if (imageFile.getName().equals("Oregon Scientific DS6639 - DSC_0307.JPG")) {
-				continue;
-			}
-
-			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 = createTempFile("removed", ".jpg");
-				Debug.debug("tempFile", tempFile);
-				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 = createTempFile("inserted" + "_", ".jpg");
-				Debug.debug("tempFile", tempFile);
-				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,
-				TiffOutputSet outputSet) throws ImageReadException,
-				IOException, ImageWriteException;
-	}
-
-	private void rewrite(Rewriter rewriter, String name) throws IOException,
-			ImageReadException, ImageWriteException
-	{
-		List images = getImagesWithExifData();
-		for (int i = 0; i < images.size(); i++)
-		{
-			if(i%10==0)
-			Debug.purgeMemory();
-
-			File imageFile = (File) images.get(i);
-			
-			// This test image contains invalid EXIF and would break the test.
-			if (imageFile.getName().equals("Oregon Scientific DS6639 - DSC_0307.JPG")) {
-				continue;
-			}
-
-			try
-			{
-
-				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 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 = createTempFile(name + "_", ".jpg");
-				Debug.debug("tempFile", tempFile);
-				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;
-			}
-
-		}
-	}
-
-	public void testRewriteLossy() throws IOException, ImageReadException,
-			ImageWriteException
-	{
-		Rewriter rewriter = new Rewriter()
-		{
-			public void rewrite(ByteSource byteSource, OutputStream os,
-					TiffOutputSet outputSet) throws ImageReadException,
-					IOException, ImageWriteException
-			{
-				new ExifRewriter().updateExifMetadataLossy(byteSource, os,
-						outputSet);
-			}
-		};
-
-		rewrite(rewriter, "lossy");
-	}
-
-	public void testRewriteLossless() throws IOException, ImageReadException,
-			ImageWriteException
-	{
-		Rewriter rewriter = new Rewriter()
-		{
-			public void rewrite(ByteSource byteSource, OutputStream os,
-					TiffOutputSet outputSet) throws ImageReadException,
-					IOException, ImageWriteException
-			{
-				new ExifRewriter().updateExifMetadataLossless(byteSource, os,
-						outputSet);
-			}
-		};
-
-		rewrite(rewriter, "lossless");
-	}
-
-	private Hashtable makeDirectoryMap(ArrayList directories)
-	{
-		Hashtable directoryMap = new Hashtable();
-		for (int i = 0; i < directories.size(); i++)
-		{
-			TiffImageMetadata.Directory directory = (TiffImageMetadata.Directory) directories
-					.get(i);
-			directoryMap.put(new Integer(directory.type), directory);
-		}
-		return directoryMap;
-	}
-
-	private Hashtable makeFieldMap(ArrayList items)
-	{
-		Hashtable fieldMap = new Hashtable();
-		for (int i = 0; i < items.size(); i++)
-		{
-			TiffImageMetadata.Item item = (TiffImageMetadata.Item) items.get(i);
-			TiffField field = item.getTiffField();
-			Object key = new Integer(field.tag);
-			if (!fieldMap.containsKey(key))
-				fieldMap.put(key, field);
-		}
-		return fieldMap;
-	}
-
-	private void compare(TiffImageMetadata oldExifMetadata,
-			TiffImageMetadata newExifMetadata) throws ImageReadException
-	{
-		assertNotNull(oldExifMetadata);
-		assertNotNull(newExifMetadata);
-
-		ArrayList oldDirectories = oldExifMetadata.getDirectories();
-		ArrayList newDirectories = newExifMetadata.getDirectories();
-
-		assertTrue(oldDirectories.size() == newDirectories.size());
-
-		Hashtable oldDirectoryMap = makeDirectoryMap(oldDirectories);
-		Hashtable newDirectoryMap = makeDirectoryMap(newDirectories);
-
-		assertEquals(oldDirectories.size(), oldDirectoryMap.keySet().size());
-		ArrayList oldDirectoryTypes = new ArrayList(oldDirectoryMap.keySet());
-		Collections.sort(oldDirectoryTypes);
-		ArrayList newDirectoryTypes = new ArrayList(newDirectoryMap.keySet());
-		Collections.sort(newDirectoryTypes);
-		assertEquals(oldDirectoryTypes, newDirectoryTypes);
-
-		for (int i = 0; i < oldDirectoryTypes.size(); i++)
-		{
-			Integer dirType = (Integer) oldDirectoryTypes.get(i);
-
-			//			Debug.debug("dirType", dirType);
-
-			TiffImageMetadata.Directory oldDirectory = (TiffImageMetadata.Directory) oldDirectoryMap
-					.get(dirType);
-			TiffImageMetadata.Directory newDirectory = (TiffImageMetadata.Directory) newDirectoryMap
-					.get(dirType);
-			assertNotNull(oldDirectory);
-			assertNotNull(newDirectory);
-
-			ArrayList oldItems = oldDirectory.getItems();
-			ArrayList newItems = newDirectory.getItems();
-
-			//			Debug.debug("oldItems.size()", oldItems.size());
-			//			Debug.debug("newItems.size()", newItems.size());
-			//			dump("oldItems", oldItems);
-			//			dump("newItems", newItems);
-
-			//			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(oldFieldMap.keySet(), newFieldMap.keySet());
-			//			assertEquals(oldFieldMap.keySet(), newFieldMap.keySet());
-
-			ArrayList oldFieldTags = new ArrayList(oldFieldMap.keySet());
-			Collections.sort(oldFieldTags);
-			ArrayList newFieldTags = new ArrayList(newFieldMap.keySet());
-			Collections.sort(newFieldTags);
-			assertEquals(oldFieldTags, newFieldTags);
-
-			for (int j = 0; j < oldFieldTags.size(); j++)
-			{
-				Integer fieldTag = (Integer) oldFieldTags.get(j);
-
-				TiffField oldField = (TiffField) oldFieldMap.get(fieldTag);
-				TiffField newField = (TiffField) newFieldMap.get(fieldTag);
-
-				//				Debug.debug("fieldTag", fieldTag);
-				//				Debug.debug("oldField", oldField);
-				//				Debug.debug("newField", newField);
-
-				//				fieldTag.
-				assertNotNull(oldField);
-				assertNotNull(newField);
-
-				assertEquals(oldField.tag, newField.tag);
-				assertEquals(dirType.intValue(), newField.directoryType);
-				assertEquals(oldField.directoryType, newField.directoryType);
-				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.tagInfo.isText())
-						;
-					else if (oldField.isLocalValue())
-					{
-						//						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);
-					}
-				}
-
-			}
-
-			//			Debug.debug();
-		}
-	}
-
-	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);
-			assertTrue("0x" + Integer.toHexString(0xff & a[i]) + " != " + "0x" + Integer.toHexString(0xff & b[i]), 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]);
-	}
+    //    public ExifRewriteTest(String name)
+    //    {
+    //        super(name);
+    //    }
+
+    public void testRemove() throws IOException, ImageReadException,
+            ImageWriteException
+    {
+        List images = getImagesWithExifData();
+        for (int i = 0; i < images.size(); i++)
+        {
+            if(i%10==0)
+            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 metadata = (JpegImageMetadata) Sanselan
+                        .getMetadata(imageFile);
+                //                assertNotNull(metadata.getExif());
+            }
+
+            {
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                new ExifRewriter().removeExifMetadata(byteSource, baos);
+                byte bytes[] = baos.toByteArray();
+                File tempFile = createTempFile("test", ".jpg");
+                Debug.debug("tempFile", tempFile);
+                IOUtils.writeToFile(bytes, tempFile);
+
+                Debug.debug("Output Segments:");
+                new JpegUtils().dumpJFIF(new ByteSourceArray(bytes));
+
+                assertTrue(!hasExifData(tempFile));
+            }
+        }
+    }
+
+    public void testInsert() throws IOException, ImageReadException,
+            ImageWriteException
+    {
+        List images = getImagesWithExifData();
+        for (int i = 0; i < images.size(); i++)
+        {
+            if(i%10==0)
+            Debug.purgeMemory();
+
+            File imageFile = (File) images.get(i);
+            Debug.debug("imageFile", imageFile);
+
+            // This test image contains invalid EXIF and would break the test.
+            if (imageFile.getName().equals("Oregon Scientific DS6639 - DSC_0307.JPG")) {
+                continue;
+            }
+
+            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 = createTempFile("removed", ".jpg");
+                Debug.debug("tempFile", tempFile);
+                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 = createTempFile("inserted" + "_", ".jpg");
+                Debug.debug("tempFile", tempFile);
+                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,
+                TiffOutputSet outputSet) throws ImageReadException,
+                IOException, ImageWriteException;
+    }
+
+    private void rewrite(Rewriter rewriter, String name) throws IOException,
+            ImageReadException, ImageWriteException
+    {
+        List images = getImagesWithExifData();
+        for (int i = 0; i < images.size(); i++)
+        {
+            if(i%10==0)
+            Debug.purgeMemory();
+
+            File imageFile = (File) images.get(i);
+
+            // This test image contains invalid EXIF and would break the test.
+            if (imageFile.getName().equals("Oregon Scientific DS6639 - DSC_0307.JPG")) {
+                continue;
+            }
+
+            try
+            {
+
+                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 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 = createTempFile(name + "_", ".jpg");
+                Debug.debug("tempFile", tempFile);
+                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;
+            }
+
+        }
+    }
+
+    public void testRewriteLossy() throws IOException, ImageReadException,
+            ImageWriteException
+    {
+        Rewriter rewriter = new Rewriter()
+        {
+            public void rewrite(ByteSource byteSource, OutputStream os,
+                    TiffOutputSet outputSet) throws ImageReadException,
+                    IOException, ImageWriteException
+            {
+                new ExifRewriter().updateExifMetadataLossy(byteSource, os,
+                        outputSet);
+            }
+        };
+
+        rewrite(rewriter, "lossy");
+    }
+
+    public void testRewriteLossless() throws IOException, ImageReadException,
+            ImageWriteException
+    {
+        Rewriter rewriter = new Rewriter()
+        {
+            public void rewrite(ByteSource byteSource, OutputStream os,
+                    TiffOutputSet outputSet) throws ImageReadException,
+                    IOException, ImageWriteException
+            {
+                new ExifRewriter().updateExifMetadataLossless(byteSource, os,
+                        outputSet);
+            }
+        };
+
+        rewrite(rewriter, "lossless");
+    }
+
+    private Hashtable makeDirectoryMap(ArrayList directories)
+    {
+        Hashtable directoryMap = new Hashtable();
+        for (int i = 0; i < directories.size(); i++)
+        {
+            TiffImageMetadata.Directory directory = (TiffImageMetadata.Directory) directories
+                    .get(i);
+            directoryMap.put(new Integer(directory.type), directory);
+        }
+        return directoryMap;
+    }
+
+    private Hashtable makeFieldMap(ArrayList items)
+    {
+        Hashtable fieldMap = new Hashtable();
+        for (int i = 0; i < items.size(); i++)
+        {
+            TiffImageMetadata.Item item = (TiffImageMetadata.Item) items.get(i);
+            TiffField field = item.getTiffField();
+            Object key = new Integer(field.tag);
+            if (!fieldMap.containsKey(key))
+                fieldMap.put(key, field);
+        }
+        return fieldMap;
+    }
+
+    private void compare(TiffImageMetadata oldExifMetadata,
+            TiffImageMetadata newExifMetadata) throws ImageReadException
+    {
+        assertNotNull(oldExifMetadata);
+        assertNotNull(newExifMetadata);
+
+        ArrayList oldDirectories = oldExifMetadata.getDirectories();
+        ArrayList newDirectories = newExifMetadata.getDirectories();
+
+        assertTrue(oldDirectories.size() == newDirectories.size());
+
+        Hashtable oldDirectoryMap = makeDirectoryMap(oldDirectories);
+        Hashtable newDirectoryMap = makeDirectoryMap(newDirectories);
+
+        assertEquals(oldDirectories.size(), oldDirectoryMap.keySet().size());
+        ArrayList oldDirectoryTypes = new ArrayList(oldDirectoryMap.keySet());
+        Collections.sort(oldDirectoryTypes);
+        ArrayList newDirectoryTypes = new ArrayList(newDirectoryMap.keySet());
+        Collections.sort(newDirectoryTypes);
+        assertEquals(oldDirectoryTypes, newDirectoryTypes);
+
+        for (int i = 0; i < oldDirectoryTypes.size(); i++)
+        {
+            Integer dirType = (Integer) oldDirectoryTypes.get(i);
+
+            //            Debug.debug("dirType", dirType);
+
+            TiffImageMetadata.Directory oldDirectory = (TiffImageMetadata.Directory) oldDirectoryMap
+                    .get(dirType);
+            TiffImageMetadata.Directory newDirectory = (TiffImageMetadata.Directory) newDirectoryMap
+                    .get(dirType);
+            assertNotNull(oldDirectory);
+            assertNotNull(newDirectory);
+
+            ArrayList oldItems = oldDirectory.getItems();
+            ArrayList newItems = newDirectory.getItems();
+
+            //            Debug.debug("oldItems.size()", oldItems.size());
+            //            Debug.debug("newItems.size()", newItems.size());
+            //            dump("oldItems", oldItems);
+            //            dump("newItems", newItems);
+
+            //            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(oldFieldMap.keySet(), newFieldMap.keySet());
+            //            assertEquals(oldFieldMap.keySet(), newFieldMap.keySet());
+
+            ArrayList oldFieldTags = new ArrayList(oldFieldMap.keySet());
+            Collections.sort(oldFieldTags);
+            ArrayList newFieldTags = new ArrayList(newFieldMap.keySet());
+            Collections.sort(newFieldTags);
+            assertEquals(oldFieldTags, newFieldTags);
+
+            for (int j = 0; j < oldFieldTags.size(); j++)
+            {
+                Integer fieldTag = (Integer) oldFieldTags.get(j);
+
+                TiffField oldField = (TiffField) oldFieldMap.get(fieldTag);
+                TiffField newField = (TiffField) newFieldMap.get(fieldTag);
+
+                //                Debug.debug("fieldTag", fieldTag);
+                //                Debug.debug("oldField", oldField);
+                //                Debug.debug("newField", newField);
+
+                //                fieldTag.
+                assertNotNull(oldField);
+                assertNotNull(newField);
+
+                assertEquals(oldField.tag, newField.tag);
+                assertEquals(dirType.intValue(), newField.directoryType);
+                assertEquals(oldField.directoryType, newField.directoryType);
+                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.tagInfo.isText())
+                        ;
+                    else if (oldField.isLocalValue())
+                    {
+                        //                        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);
+                    }
+                }
+
+            }
+
+            //            Debug.debug();
+        }
+    }
+
+    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);
+            assertTrue("0x" + Integer.toHexString(0xff & a[i]) + " != " + "0x" + Integer.toHexString(0xff & b[i]), 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]);
+    }
 }

Modified: commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/GpsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/GpsTest.java?rev=995634&r1=995633&r2=995634&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/GpsTest.java (original)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/GpsTest.java Fri Sep 10 01:35:50 2010
@@ -31,68 +31,68 @@ import org.apache.sanselan.util.Debug;
 public class GpsTest extends ExifBaseTest implements SanselanConstants
 {
 
-	public void test() throws Exception
-	{
+    public void test() throws Exception
+    {
 
-		List images = getImagesWithExifData(300);
-		for (int i = 0; i < images.size(); i++)
-		{
-			if (i % 10 == 0)
-				Debug.purgeMemory();
-
-			File imageFile = (File) images.get(i);
-
-//			Debug.debug();
-//			Debug.debug("imageFile", imageFile);
-
-			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("gpsInfo longitude as degrees east", gpsInfo
-						.getLongitudeAsDegreesEast());
-				Debug.debug("gpsInfo latitude as degrees north", gpsInfo
-						.getLatitudeAsDegreesNorth());
-
-				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;
-			}
-		}
+        List images = getImagesWithExifData(300);
+        for (int i = 0; i < images.size(); i++)
+        {
+            if (i % 10 == 0)
+                Debug.purgeMemory();
+
+            File imageFile = (File) images.get(i);
+
+//            Debug.debug();
+//            Debug.debug("imageFile", imageFile);
+
+            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("gpsInfo longitude as degrees east", gpsInfo
+                        .getLongitudeAsDegreesEast());
+                Debug.debug("gpsInfo latitude as degrees north", gpsInfo
+                        .getLatitudeAsDegreesNorth());
+
+                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;
+            }
+        }
 
-	}
+    }
 }

Modified: commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java?rev=995634&r1=995633&r2=995634&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java (original)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java Fri Sep 10 01:35:50 2010
@@ -27,46 +27,46 @@ 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);
-		//		}
+    //    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);
+        //        }
 
-	}
+    }
 
 }

Modified: commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/SpecificExifTagTest.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/SpecificExifTagTest.java?rev=995634&r1=995633&r2=995634&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/SpecificExifTagTest.java (original)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/SpecificExifTagTest.java Fri Sep 10 01:35:50 2010
@@ -34,68 +34,68 @@ import org.apache.sanselan.formats.tiff.
 import org.apache.sanselan.util.Debug;
 
 public abstract class SpecificExifTagTest extends ExifBaseTest
-		implements
-			AllTagConstants
+        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++)
-		{
-			if(i%10==0)
-			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);
-		}
+    //    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++)
+        {
+            if(i%10==0)
+            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);
+        }
 
-	}
+    }
 
 }

Modified: commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/TextFieldTest.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/TextFieldTest.java?rev=995634&r1=995633&r2=995634&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/TextFieldTest.java (original)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/TextFieldTest.java Fri Sep 10 01:35:50 2010
@@ -27,47 +27,47 @@ 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;
-		}
+    //    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;
+        }
 
-	}
+    }
 
 }

Modified: commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java?rev=995634&r1=995633&r2=995634&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java (original)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java Fri Sep 10 01:35:50 2010
@@ -29,75 +29,75 @@ import org.apache.sanselan.sampleUsage.W
 import org.apache.sanselan.util.Debug;
 
 public class WriteExifMetadataExampleTest extends ExifBaseTest
-		implements
-			AllTagConstants
+        implements
+            AllTagConstants
 {
-	//	public WriteExifMetadataExampleTest(String name)
-	//	{
-	//		super(name);
-	//	}
-
-	public void test() throws IOException, ImageReadException,
-			ImageWriteException
-	{
-		List images = getJpegImages();
-		for (int i = 0; i < images.size(); i++)
-		{
-			if (i % 10 == 0)
-				Debug.purgeMemory();
-
-			File imageFile = (File) images.get(i);
-			Debug.debug("imageFile", imageFile.getAbsoluteFile());
-
-			File tempFile = createTempFile("test", ".jpg");
-			Debug.debug("tempFile", tempFile.getAbsoluteFile());
-
-			try
-			{
-				boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
-				if (ignoreImageData)
-					continue;
-				new WriteExifMetadataExample().changeExifMetadata(imageFile,
-						tempFile);
-			}
-			catch (ExifRewriter.ExifOverflowException e)
-			{
-				Debug.debug("Error image", imageFile.getAbsoluteFile());
-				Debug.debug(e, 4);
-			}
-		}
-	}
-
-	public void testInsert() throws IOException, ImageReadException,
-			ImageWriteException
-	{
-		List images = getJpegImages();
-		for (int i = 0; i < images.size(); i++)
-		{
-			if (i % 10 == 0)
-				Debug.purgeMemory();
-
-			File imageFile = (File) images.get(i);
-			Debug.debug("imageFile", imageFile.getAbsoluteFile());
-
-			File tempFile = createTempFile("test", ".jpg");
-			Debug.debug("tempFile", tempFile.getAbsoluteFile());
-
-			try
-			{
-				boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
-				if (ignoreImageData)
-					continue;
-				new WriteExifMetadataExample().changeExifMetadata(imageFile,
-						tempFile);
-			}
-			catch (ExifRewriter.ExifOverflowException e)
-			{
-				Debug.debug("Ignoring unavoidable ExifOverflowException", e.getMessage());
-				Debug.debug("Error image", imageFile.getAbsoluteFile());
-//				Debug.debug(e, 4);
-			}
-		}
-	}
+    //    public WriteExifMetadataExampleTest(String name)
+    //    {
+    //        super(name);
+    //    }
+
+    public void test() throws IOException, ImageReadException,
+            ImageWriteException
+    {
+        List images = getJpegImages();
+        for (int i = 0; i < images.size(); i++)
+        {
+            if (i % 10 == 0)
+                Debug.purgeMemory();
+
+            File imageFile = (File) images.get(i);
+            Debug.debug("imageFile", imageFile.getAbsoluteFile());
+
+            File tempFile = createTempFile("test", ".jpg");
+            Debug.debug("tempFile", tempFile.getAbsoluteFile());
+
+            try
+            {
+                boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+                if (ignoreImageData)
+                    continue;
+                new WriteExifMetadataExample().changeExifMetadata(imageFile,
+                        tempFile);
+            }
+            catch (ExifRewriter.ExifOverflowException e)
+            {
+                Debug.debug("Error image", imageFile.getAbsoluteFile());
+                Debug.debug(e, 4);
+            }
+        }
+    }
+
+    public void testInsert() throws IOException, ImageReadException,
+            ImageWriteException
+    {
+        List images = getJpegImages();
+        for (int i = 0; i < images.size(); i++)
+        {
+            if (i % 10 == 0)
+                Debug.purgeMemory();
+
+            File imageFile = (File) images.get(i);
+            Debug.debug("imageFile", imageFile.getAbsoluteFile());
+
+            File tempFile = createTempFile("test", ".jpg");
+            Debug.debug("tempFile", tempFile.getAbsoluteFile());
+
+            try
+            {
+                boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+                if (ignoreImageData)
+                    continue;
+                new WriteExifMetadataExample().changeExifMetadata(imageFile,
+                        tempFile);
+            }
+            catch (ExifRewriter.ExifOverflowException e)
+            {
+                Debug.debug("Ignoring unavoidable ExifOverflowException", e.getMessage());
+                Debug.debug("Error image", imageFile.getAbsoluteFile());
+//                Debug.debug(e, 4);
+            }
+        }
+    }
 
 }

Modified: commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcBaseTest.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcBaseTest.java?rev=995634&r1=995633&r2=995634&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcBaseTest.java (original)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcBaseTest.java Fri Sep 10 01:35:50 2010
@@ -29,77 +29,77 @@ import org.apache.sanselan.formats.jpeg.
 
 public abstract class IptcBaseTest extends SanselanTest
 {
-	protected static boolean hasIptcData(File file)
-	{
-		//		Debug.debug("hasIptcData file", file.getAbsoluteFile());
-
-		if (!file.getName().toLowerCase().endsWith(".jpg"))
-			return false;
-		//ImageFormat format = Sanselan.guessFormat(file);
-		//if (format != ImageFormat.IMAGE_FORMAT_JPEG)
-		//	return false;
-
-		try
-		{
-			ByteSource byteSource = new ByteSourceFile(file);
-			return new JpegImageParser().hasIptcSegment(byteSource);
-		}
-		catch (Exception e)
-		{
-			//			Debug.debug("Error file", file.getAbsoluteFile());
-			//			Debug.debug(e, 4);
-			return false;
-		}
-	}
-
-	private static final ImageFilter HAS_IPTC_IMAGE_FILTER = new ImageFilter()
-	{
-		public boolean accept(File file) throws IOException, ImageReadException
-		{
-			return hasIptcData(file);
-		}
-	};
-
-	private static final ImageFilter JPEG_IMAGE_FILTER = new ImageFilter()
-	{
-		public boolean accept(File file) throws IOException, ImageReadException
-		{
-			return file.getName().toLowerCase().endsWith(".jpg");
-		}
-	};
-
-	protected File getImageWithIptcData() throws IOException,
-			ImageReadException
-	{
-		return getTestImage(HAS_IPTC_IMAGE_FILTER);
-	}
-
-	protected List getImagesWithIptcData() throws IOException,
-			ImageReadException
-	{
-		return getTestImages(HAS_IPTC_IMAGE_FILTER);
-	}
-
-	protected List getImagesWithIptcData(int max) throws IOException,
-			ImageReadException
-	{
-		return getTestImages(HAS_IPTC_IMAGE_FILTER, max);
-	}
-
-	protected File getJpegImage() throws IOException, ImageReadException
-	{
-		return getTestImage(JPEG_IMAGE_FILTER);
-	}
-
-	protected List getJpegImages() throws IOException, ImageReadException
-	{
-		return getTestImages(JPEG_IMAGE_FILTER);
-	}
-
-	protected List getJpegImages(int max) throws IOException,
-			ImageReadException
-	{
-		return getTestImages(JPEG_IMAGE_FILTER, max);
-	}
+    protected static boolean hasIptcData(File file)
+    {
+        //        Debug.debug("hasIptcData file", file.getAbsoluteFile());
+
+        if (!file.getName().toLowerCase().endsWith(".jpg"))
+            return false;
+        //ImageFormat format = Sanselan.guessFormat(file);
+        //if (format != ImageFormat.IMAGE_FORMAT_JPEG)
+        //    return false;
+
+        try
+        {
+            ByteSource byteSource = new ByteSourceFile(file);
+            return new JpegImageParser().hasIptcSegment(byteSource);
+        }
+        catch (Exception e)
+        {
+            //            Debug.debug("Error file", file.getAbsoluteFile());
+            //            Debug.debug(e, 4);
+            return false;
+        }
+    }
+
+    private static final ImageFilter HAS_IPTC_IMAGE_FILTER = new ImageFilter()
+    {
+        public boolean accept(File file) throws IOException, ImageReadException
+        {
+            return hasIptcData(file);
+        }
+    };
+
+    private static final ImageFilter JPEG_IMAGE_FILTER = new ImageFilter()
+    {
+        public boolean accept(File file) throws IOException, ImageReadException
+        {
+            return file.getName().toLowerCase().endsWith(".jpg");
+        }
+    };
+
+    protected File getImageWithIptcData() throws IOException,
+            ImageReadException
+    {
+        return getTestImage(HAS_IPTC_IMAGE_FILTER);
+    }
+
+    protected List getImagesWithIptcData() throws IOException,
+            ImageReadException
+    {
+        return getTestImages(HAS_IPTC_IMAGE_FILTER);
+    }
+
+    protected List getImagesWithIptcData(int max) throws IOException,
+            ImageReadException
+    {
+        return getTestImages(HAS_IPTC_IMAGE_FILTER, max);
+    }
+
+    protected File getJpegImage() throws IOException, ImageReadException
+    {
+        return getTestImage(JPEG_IMAGE_FILTER);
+    }
+
+    protected List getJpegImages() throws IOException, ImageReadException
+    {
+        return getTestImages(JPEG_IMAGE_FILTER);
+    }
+
+    protected List getJpegImages(int max) throws IOException,
+            ImageReadException
+    {
+        return getTestImages(JPEG_IMAGE_FILTER, max);
+    }
 
 }

Modified: commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcDumpTest.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcDumpTest.java?rev=995634&r1=995633&r2=995634&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcDumpTest.java (original)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcDumpTest.java Fri Sep 10 01:35:50 2010
@@ -32,53 +32,53 @@ import org.apache.sanselan.util.Debug;
 public class IptcDumpTest extends IptcBaseTest
 {
 
-	public void test() throws IOException, ImageReadException
-	{
-		List images = getImagesWithIptcData();
-		for (int i = 0; i < images.size(); i++)
-		{
-			if (i % 10 == 0)
-				Debug.purgeMemory();
-
-			File imageFile = (File) images.get(i);
-			Debug.debug("imageFile", imageFile);
-			Debug.debug();
-
-			// ByteSource byteSource = new ByteSourceFile(imageFile);
-			// Debug.debug("Segments:");
-			// new JpegUtils().dumpJFIF(byteSource);
-
-			Map params = new HashMap();
-			boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
-			params
-					.put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
-							!ignoreImageData));
-			// params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
-
-			JpegImageMetadata metadata = (JpegImageMetadata) Sanselan
-					.getMetadata(imageFile, params);
-			assertNotNull(metadata);
-			assertNotNull(metadata.getPhotoshop());
-
-			metadata.getPhotoshop().dump();
-			// if(metadata.getPhotoshop().getItems().size()>0)
-			// Debug.debug("iptc size",
-			// metadata.getPhotoshop().getItems().size());
-
-			JpegPhotoshopMetadata psMetadata = metadata.getPhotoshop();
-			List oldRecords = psMetadata.photoshopApp13Data.getRecords();
-
-			System.out.println();
-			for (int j = 0; j < oldRecords.size(); j++)
-			{
-				IPTCRecord record = (IPTCRecord) oldRecords.get(j);
-				if (record.iptcType.type != IPTCConstants.IPTC_TYPE_CITY.type)
-					System.out.println("Key: " + record.iptcType.name + " (0x"
-							+ Integer.toHexString(record.iptcType.type)
-							+ "), value: " + record.value);
-			}
-			System.out.println();
-		}
-	}
+    public void test() throws IOException, ImageReadException
+    {
+        List images = getImagesWithIptcData();
+        for (int i = 0; i < images.size(); i++)
+        {
+            if (i % 10 == 0)
+                Debug.purgeMemory();
+
+            File imageFile = (File) images.get(i);
+            Debug.debug("imageFile", imageFile);
+            Debug.debug();
+
+            // ByteSource byteSource = new ByteSourceFile(imageFile);
+            // Debug.debug("Segments:");
+            // new JpegUtils().dumpJFIF(byteSource);
+
+            Map params = new HashMap();
+            boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+            params
+                    .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
+                            !ignoreImageData));
+            // params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
+
+            JpegImageMetadata metadata = (JpegImageMetadata) Sanselan
+                    .getMetadata(imageFile, params);
+            assertNotNull(metadata);
+            assertNotNull(metadata.getPhotoshop());
+
+            metadata.getPhotoshop().dump();
+            // if(metadata.getPhotoshop().getItems().size()>0)
+            // Debug.debug("iptc size",
+            // metadata.getPhotoshop().getItems().size());
+
+            JpegPhotoshopMetadata psMetadata = metadata.getPhotoshop();
+            List oldRecords = psMetadata.photoshopApp13Data.getRecords();
+
+            System.out.println();
+            for (int j = 0; j < oldRecords.size(); j++)
+            {
+                IPTCRecord record = (IPTCRecord) oldRecords.get(j);
+                if (record.iptcType.type != IPTCConstants.IPTC_TYPE_CITY.type)
+                    System.out.println("Key: " + record.iptcType.name + " (0x"
+                            + Integer.toHexString(record.iptcType.type)
+                            + "), value: " + record.value);
+            }
+            System.out.println();
+        }
+    }
 
 }



Mime
View raw message