1. jhove2
  2. main

Commits

Stephen Abrams  committed 51a43b9 Merge

Merge fix for issue #114

  • Participants
  • Parent commits 614875f, 954069f
  • Branches default

Comments (0)

Files changed (4)

File src/main/java/org/jhove2/module/format/tiff/IFDEntry.java

View file
      *  used to read the value into the proper value type object */
     protected long savedValueOffset;
 
-    /** Contains the value iff the value is 4 or less bytes.  Otherwise is offset to value 
+    /** offset to the IFDEntry being parsed */
+    protected long tagOffset;
+    
+    /** Contains the value iff the value is 4 or less bytes.  
      * Otherwise it is the offset of value */
     protected long valueOffset;
 
         throws IOException, JHOVE2Exception
     {
         this.isValid = Validity.True;
+        this.tagOffset = input.getPosition();
         this.tag = input.readUnsignedShort();
         if (this.tag > prevTag)
             prevTag = this.tag;
         else {
             this.isValid = Validity.False;
-            Object[]messageArgs = new Object[]{tag, input.getPosition()};
+            Object[]messageArgs = new Object[]{tag, this.tagOffset};
             this.TagSortOrderErrorMessage = (new Message(Severity.ERROR,
                     Context.OBJECT,
                     "org.jhove2.module.format.tiff.IFD.TagSortOrderErrorMessage",
 
         /* Skip over tags with unknown type; those outside of defined range. */
         if (this.type < TiffType.BYTE.num()|| this.type > TiffType.IFD.num()) {
-            Object[]messageArgs = new Object[] {this.type, input.getPosition() };
+            Object[]messageArgs = new Object[] {this.type, this.tagOffset };
             this.unknownTypeMessages.add(new Message(Severity.WARNING,
                     Context.OBJECT,
                     "org.jhove2.module.format.tiff.IFD.UnknownTypeMessage",
      * 
      * isValidTag 
      * 
-     *  1) if tag is known and defined
-     *  2) that the type matches expected type values for that tag definition
-     *  3) that count expected matches the count read in
+     *  1) that the type matches expected type values for that tag definition
+     *  2) that count expected matches the count read in
      *  
      * @param jhove2
      * @return boolean 
             checkCount(jhove2, this.count, this.tagDefinition.getCardinality());
         }
         else {
-            this.isValid = Validity.False;
-            Object[]messageArgs = new Object[]{this.tag, this.valueOffset};
+            Object[]messageArgs = new Object[]{this.tag, tagOffset};
             this.UnknownTagMessage = (new Message(Severity.WARNING,
                     Context.OBJECT,
                     "org.jhove2.module.format.tiff.IFDEntry.UnknownTagMessage",
                     messageArgs, jhove2.getConfigInfo()));  
-            isValid = false;
         }
         return isValid;
     }
             else if (type.equals(TiffType.SHORT)) {
                 this.shortValue = new Short(input.readUnsignedShort());
                 // store in Long type if it can be SHORT or LONG 
-                if (this.tagDefinition.getType().contains("LONG")) 
+                if (this.tagDefinition != null && this.tagDefinition.getType().contains("LONG")) 
                     this.longValue = new Long (shortValue.getValue());
             }
             else if (type.equals(TiffType.LONG)) {
                 this.shortArrayValue = new ShortArray();
                 this.shortArrayValue.setValue(input, this.count);
                 // store in Long type if it can be SHORT or LONG 
-                if (this.tagDefinition.getType().contains("LONG")) {
+                if (this.tagDefinition != null && this.tagDefinition.getType().contains("LONG")) {
                     this.longArrayValue = new LongArray (shortArrayValue.getShortArrayValue());
                 }
             }
             }
             else if (type.equals(TiffType.SHORT)) {
                 // if value can be LONG or SHORT return the value stored in Long 
-                if (this.tagDefinition.getType().contains("LONG")) 
+                if (this.tagDefinition != null && this.tagDefinition.getType().contains("LONG")) 
                     return this.longArrayValue;
                 else
                     return this.shortArrayValue;
             }
             else if (type.equals(TiffType.SHORT)) {
                 // if value can be LONG or SHORT return the value stored in Long 
-                if (this.tagDefinition.getType().contains("LONG")) {
+                if (this.tagDefinition != null && this.tagDefinition.getType().contains("LONG")) {
                     return this.longValue;
                 }
                 else {

File src/test/java/org/jhove2/module/format/tiff/EmbeddedFormatTest.java

View file
+/**
+ * 
+ */
+package org.jhove2.module.format.tiff;
+
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.jhove2.core.JHOVE2Exception;
+import org.jhove2.module.format.tiff.type.Short;
+import org.jhove2.module.format.tiff.type.desc.Compression;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author mstrong
+ *
+ */
+public class EmbeddedFormatTest extends TiffModuleTestBase{
+
+    private String blueSquareTif;
+    IFDEntry ifdEntry = null;
+
+    /**
+     * @throws java.lang.Exception
+     */
+    @Before
+    public void setUp() throws Exception {       
+        parse(blueSquareTif);
+    }
+
+    /**
+     * Test methods for TIFF Parser 
+     */
+    @Test
+    public void testCompressionDescriptionValue()  {
+        // read in the compression value 
+        String compression_d = null;
+        List<IFD> ifdList = testTiffModule.getIFDs();
+        for (IFD ifd : ifdList) {
+            Map<Integer, IFDEntry> ifdEntryList = ifd.getEntries();
+            if ((ifdEntry = ifdEntryList.get(TiffIFD.COMPRESSION)) != null) {
+                int scheme = ((Short) ifdEntry.getValue()).getValue();
+                 /* set the descriptive format for the Compression Scheme */
+                Compression compression = null;
+                try {
+                    compression = Compression.getCompressionValue(scheme, this.getJHOVE2());
+                    if (compression != null) {
+                        compression_d = compression.getDescription();
+                        assertTrue("Compression description value: <" + compression_d + "> is not as expected", compression_d.equalsIgnoreCase("No Compression"));
+                    }
+                }
+                catch (JHOVE2Exception e) {
+                    e.printStackTrace();
+                }
+                catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+    /**
+     * Tests that Tiff File has 2 child sources (ICCProfile & XMP)
+     * 
+     */
+    @Test
+    public void testICCProfileExists() {
+        int size = 0;
+        try {
+            size = fileSource.getChildSources().size();
+        }
+        catch (JHOVE2Exception e) {
+            e.printStackTrace();
+        }
+        assertTrue("Not all child sources reported", size == 2);
+        List<IFD> ifdList = testTiffModule.getIFDs();
+        for (IFD ifd : ifdList) {
+            Map<Integer, IFDEntry> ifdEntryList = ifd.getEntries();
+            IFDEntry ifdEntry = null;
+            ifdEntry = ifdEntryList.get(TiffIFD.ICCPROFILE);
+            assertTrue("ICCPRofile flagged", ifdEntry != null);
+        }
+    }
+
+    public String getBlueSquareTif() {
+        return blueSquareTif;
+    }
+
+    @Resource
+    public void setBlueSquareTif(String blueSquareTif) {
+        this.blueSquareTif = blueSquareTif;
+    }
+
+
+}

File src/test/java/org/jhove2/module/format/tiff/IntelTiffFileTest.java

View file
 import java.nio.ByteOrder;
 import java.util.List;
 import java.util.Map;
+import org.jhove2.module.format.tiff.type.Short;
 
 import javax.annotation.Resource;
 
     }
 
     @Test
-    public void testIFDEntryParseMessages() {
+    public void testTagExistence() {
         List<IFD> ifdList = testTiffModule.getIFDs();
         for (IFD ifd : ifdList) {
             Map<Integer, IFDEntry> ifdEntryList = ifd.getEntries();
             IFDEntry ifdEntry = null;
-            if ((ifdEntry = ifdEntryList.get(254)) != null)
-                assertTrue("Known tag 254 flagged", ifdEntry.getUnknownTagMessage() == null);
-            if ((ifdEntry = ifdEntryList.get(34850)) == null)
-                assertTrue("Unknown tag 34850 not flagged", ifdEntry == null);
+            /* test 254 does exist and unknownTagMessage is null */
+            if ((ifdEntry = ifdEntryList.get(TiffIFD.NEWSUBFILETYPE)) != null)
+                assertTrue("Known tag 254 (NewSubfileType) flagged", ifdEntry.getUnknownTagMessage() == null);
+            /* test 34851 tag does not exist */
+            ifdEntry = ifdEntryList.get(34851);
+            assertTrue("Tag 34851 should not exist in Tiff file ", ifdEntry == null);
+        }
+    }
+
+    @Test
+    public void testUnknownTagEntry() {
+        List<IFD> ifdList = testTiffModule.getIFDs();
+        for (IFD ifd : ifdList) {
+            Map<Integer, IFDEntry> ifdEntryList = ifd.getEntries();
+            IFDEntry ifdEntry = null;
+            /* test 20515 does exist but tag is not defined */
+            if ((ifdEntry = ifdEntryList.get(20515)) != null) {
+                assertTrue("Unknown tag 20515 flagged", ifdEntry.getUnknownTagMessage() != null);
+
+                /* test that the value type is what is expected */
+                Object value = ifdEntry.getValue(); 
+                String className = value.getClass().getName();
+                assertTrue("Value type " + className + " is not of expected Short type", value instanceof org.jhove2.module.format.tiff.type.Short);
+
+                /* test that the value is as expected */
+                if (value instanceof org.jhove2.module.format.tiff.type.Short) {
+                    int shortValue = ((Short)value).getValue();
+                    assertTrue("Value of tag 20515: <" + shortValue + "> does not equal expected value of 6", shortValue==6);
+                }
+            }
         }
     }
 
     public void setIntelTestFile(String intelTestFile) {
         this.intelTestFile = intelTestFile;
     }
-
-
 }

File src/test/java/org/jhove2/module/format/tiff/InvalidDateTimeTest.java

View file
+/**
+ * 
+ */
+package org.jhove2.module.format.tiff;
+
+import static org.junit.Assert.assertTrue;
+
+import java.nio.ByteOrder;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author mstrong
+ *
+ */
+
+public class InvalidDateTimeTest extends TiffModuleTestBase{
+
+    private String invalidDateTimeFile;
+
+    /**
+     * @throws java.lang.Exception
+     */
+    @Before
+    public void setUp() throws Exception {
+        parse(invalidDateTimeFile);
+    }
+
+
+    /**
+     * Test that the InvalidDateTimeMessage is present for the DATETIME field
+     */
+    @Test
+    public void testInvalidDateTimeMessage() {
+        List<IFD> ifdList = testTiffModule.getIFDs();
+        for (IFD ifd : ifdList) {
+            Map<Integer, IFDEntry> ifdEntryList = ifd.getEntries();
+            IFDEntry ifdEntry = null;
+            
+            if ((ifdEntry = ifdEntryList.get(TiffIFD.DATETIME)) != null) {
+                assertTrue("InvalidDateTime error not flagged", ifdEntry.getInvalidDateTimeMessage() != null);
+            }
+        }
+    }
+
+    public String getInvalidDateTimeFile() {
+        return invalidDateTimeFile;
+    }
+
+    @Resource
+    public void setInvalidDateTimeFile(String invalidDateTimeFile) {
+        this.invalidDateTimeFile = invalidDateTimeFile;
+    }
+
+
+}