You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by kl...@apache.org on 2004/08/14 00:38:52 UTC
cvs commit: jakarta-poi/src/testcases/org/apache/poi/hpsf/basic TestWrite.java
klute 2004/08/13 15:38:52
Modified: src/java/org/apache/poi/hpsf ClassID.java
MutableSection.java
src/testcases/org/apache/poi/hpsf/basic TestWrite.java
Log:
Fixed a bug where a mutable section's format ID was written in the wrong byte order. Thanks to Bernd Freigang for pointing this out!
Revision Changes Path
1.14 +16 -2 jakarta-poi/src/java/org/apache/poi/hpsf/ClassID.java
Index: ClassID.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hpsf/ClassID.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ClassID.java 9 Apr 2004 13:05:16 -0000 1.13
+++ ClassID.java 13 Aug 2004 22:38:52 -0000 1.14
@@ -96,6 +96,20 @@
/**
+ * <p>Sets the bytes making out the class ID.</p>
+ *
+ * @param bytes The bytes making out the class ID in big-endian format. They
+ * are copied without their order being changed.
+ */
+ public void setBytes(final byte[] bytes)
+ {
+ for (int i = 0; i < this.bytes.length; i++)
+ this.bytes[i] = bytes[i];
+ }
+
+
+
+ /**
* <p>Reads the class ID's value from a byte array by turning
* little-endian into big-endian.</p>
*
@@ -134,7 +148,7 @@
/**
* <p>Writes the class ID to a byte array in the
- * little-endian.</p>
+ * little-endian format.</p>
*
* @param dst The byte array to write to.
*
1.11 +8 -2 jakarta-poi/src/java/org/apache/poi/hpsf/MutableSection.java
Index: MutableSection.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hpsf/MutableSection.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- MutableSection.java 22 Jun 2004 16:11:39 -0000 1.10
+++ MutableSection.java 13 Aug 2004 22:38:52 -0000 1.11
@@ -127,7 +127,13 @@
*/
public void setFormatID(final byte[] formatID)
{
- setFormatID(new ClassID(formatID, 0));
+ ClassID fid = getFormatID();
+ if (fid == null)
+ {
+ fid = new ClassID();
+ setFormatID(fid);
+ }
+ fid.setBytes(formatID);
}
1.16 +14 -6 jakarta-poi/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
Index: TestWrite.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- TestWrite.java 22 Jun 2004 16:14:56 -0000 1.15
+++ TestWrite.java 13 Aug 2004 22:38:52 -0000 1.16
@@ -1,4 +1,3 @@
-
/* ====================================================================
Copyright 2002-2004 Apache Software Foundation
@@ -38,6 +37,7 @@
import junit.framework.Assert;
import junit.framework.TestCase;
+import org.apache.poi.hpsf.ClassID;
import org.apache.poi.hpsf.Constants;
import org.apache.poi.hpsf.HPSFRuntimeException;
import org.apache.poi.hpsf.IllegalPropertySetDataException;
@@ -259,6 +259,8 @@
SummaryInformation.DEFAULT_STREAM_NAME);
r.read(new FileInputStream(filename));
Assert.assertNotNull(psa[0]);
+ Assert.assertTrue(psa[0].isSummaryInformation());
+
final Section s = (Section) (psa[0].getSections().get(0));
Object p1 = s.getProperty(PropertyIDMap.PID_AUTHOR);
Object p2 = s.getProperty(PropertyIDMap.PID_TITLE);
@@ -293,9 +295,9 @@
final MutablePropertySet ps = new MutablePropertySet();
ps.clearSections();
- final byte[] formatID =
- new byte[]{0, 1, 2, 3, 4, 5, 6, 7,
- 8, 9, 10, 11, 12, 13, 14, 15};
+ final ClassID formatID = new ClassID();
+ formatID.setBytes(new byte[]{0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 13, 14, 15});
final MutableSection s1 = new MutableSection();
s1.setFormatID(formatID);
s1.setProperty(2, SECTION1);
@@ -336,6 +338,7 @@
r.read(new FileInputStream(filename));
Assert.assertNotNull(psa[0]);
Section s = (Section) (psa[0].getSections().get(0));
+ assertEquals(s.getFormatID(), formatID);
Object p = s.getProperty(2);
Assert.assertEquals(SECTION1, p);
s = (Section) (psa[0].getSections().get(1));
@@ -529,6 +532,7 @@
byte[] bytes = out.toByteArray();
PropertySet psr = new PropertySet(bytes);
+ assertTrue(psr.isSummaryInformation());
Section sr = (Section) psr.getSections().get(0);
String title = (String) sr.getProperty(PropertyIDMap.PID_TITLE);
assertEquals(TITLE, title);
@@ -709,7 +713,7 @@
/* Compare the property set stream with the corresponding one
* from the origin file and check whether they are equal. */
- assertEquals("Equality for file "+f.getName(),ps1, ps2);
+ assertEquals("Equality for file " + f.getName(), ps1, ps2);
}
}
catch (Exception ex)
@@ -754,6 +758,10 @@
final byte[] bytes = psf[0].getBytes();
final InputStream in = new ByteArrayInputStream(bytes);
final PropertySet ps2 = PropertySetFactory.create(in);
+
+ /* Check if the result is a DocumentSummaryInformation stream, as
+ * specified. */
+ assertTrue(ps2.isDocumentSummaryInformation());
/* Compare the property set stream with the corresponding one
* from the origin file and check whether they are equal. */
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org