aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2008-11-12 15:03:38 +0000
committerNick Burch <nick@apache.org>2008-11-12 15:03:38 +0000
commit13d429e01b19f9cc052838229bbd5a77212a7b87 (patch)
tree1369c2f363ae26b0ad3d75be1bd2cd2be2160f81 /src/scratchpad
parentfadd255a55a4613466b21e97c06bb85947a4b7f1 (diff)
downloadpoi-13d429e01b19f9cc052838229bbd5a77212a7b87.tar.gz
poi-13d429e01b19f9cc052838229bbd5a77212a7b87.zip
Fix bug #46043 - correctly write out HPSF properties with HWPF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@713393 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad')
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java3
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestCase.java27
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java18
3 files changed, 32 insertions, 16 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
index f1898c082b..9bc8354a73 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
@@ -552,7 +552,8 @@ public class HWPFDocument extends POIDocument
pfs.createDocument(new ByteArrayInputStream(mainBuf), "WordDocument");
pfs.createDocument(new ByteArrayInputStream(tableBuf), "1Table");
pfs.createDocument(new ByteArrayInputStream(dataBuf), "Data");
-
+ writeProperties(pfs);
+
pfs.writeFilesystem(out);
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestCase.java b/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestCase.java
index b831851a1e..dcfa99aecd 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestCase.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestCase.java
@@ -18,6 +18,10 @@
package org.apache.poi.hwpf;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
import junit.framework.TestCase;
@@ -30,9 +34,7 @@ public abstract class HWPFTestCase
{
}
- protected void setUp()
- throws Exception
- {
+ protected void setUp() throws Exception {
super.setUp();
/**@todo verify the constructors*/
_hWPFDocFixture = new HWPFDocFixture(this);
@@ -40,13 +42,20 @@ public abstract class HWPFTestCase
_hWPFDocFixture.setUp();
}
- protected void tearDown()
- throws Exception
- {
- _hWPFDocFixture.tearDown();
+ protected void tearDown() throws Exception {
+ if(_hWPFDocFixture != null) {
+ _hWPFDocFixture.tearDown();
+ }
- _hWPFDocFixture = null;
- super.tearDown();
+ _hWPFDocFixture = null;
+ super.tearDown();
}
+ public HWPFDocument writeOutAndRead(HWPFDocument doc) throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ doc.write(baos);
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ HWPFDocument newDoc = new HWPFDocument(bais);
+ return newDoc;
+ }
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java
index 542e2d7920..2cc47474f8 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java
@@ -19,10 +19,9 @@ package org.apache.poi.hwpf.usermodel;
import java.io.File;
import java.io.FileInputStream;
-import junit.framework.TestCase;
-
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.HWPFTestCase;
import org.apache.poi.hwpf.model.StyleSheet;
/**
@@ -30,13 +29,10 @@ import org.apache.poi.hwpf.model.StyleSheet;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestProblems extends TestCase {
+public class TestProblems extends HWPFTestCase {
private String dirname = System.getProperty("HWPF.testdata.path");
- protected void setUp() throws Exception {
- }
-
/**
* ListEntry passed no ListTable
*/
@@ -165,4 +161,14 @@ public class TestProblems extends TestCase {
// Good
}
}
+
+ public void testWriteProperties() throws Exception {
+ HWPFDocument doc = new HWPFDocument(new FileInputStream(
+ new File(dirname, "SampleDoc.doc")));
+ assertEquals("Nick Burch", doc.getSummaryInformation().getAuthor());
+
+ // Write and read
+ HWPFDocument doc2 = writeOutAndRead(doc);
+ assertEquals("Nick Burch", doc.getSummaryInformation().getAuthor());
+ }
}