aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2008-03-03 15:10:46 +0000
committerNick Burch <nick@apache.org>2008-03-03 15:10:46 +0000
commit92211d73aa319ab99788ac2502d21cbbc1445c4c (patch)
treeadfffc8f881e42df7e75a235653d295ea33fd4cd /src/testcases/org
parentf191df6849a16dd49aeca8b5b794d2a17d4aa5dd (diff)
downloadpoi-92211d73aa319ab99788ac2502d21cbbc1445c4c.tar.gz
poi-92211d73aa319ab99788ac2502d21cbbc1445c4c.zip
Fix from Yegor from bug #44491 - don't have the new style handy POIDocument property stuff break old style hpsf+hssf use
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@633118 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org')
-rw-r--r--src/testcases/org/apache/poi/TestPOIDocumentMain.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java98
2 files changed, 102 insertions, 2 deletions
diff --git a/src/testcases/org/apache/poi/TestPOIDocumentMain.java b/src/testcases/org/apache/poi/TestPOIDocumentMain.java
index be3d9b0a78..5d4d7df19e 100644
--- a/src/testcases/org/apache/poi/TestPOIDocumentMain.java
+++ b/src/testcases/org/apache/poi/TestPOIDocumentMain.java
@@ -85,7 +85,8 @@ public class TestPOIDocumentMain extends TestCase {
public void testWriteProperties() throws Exception {
// Just check we can write them back out into a filesystem
POIFSFileSystem outFS = new POIFSFileSystem();
- doc.writeProperties(outFS);
+ doc.readProperties();
+ doc.writeProperties(outFS);
// Should now hold them
assertNotNull(
@@ -101,7 +102,8 @@ public class TestPOIDocumentMain extends TestCase {
// Write them out
POIFSFileSystem outFS = new POIFSFileSystem();
- doc.writeProperties(outFS);
+ doc.readProperties();
+ doc.writeProperties(outFS);
outFS.writeFilesystem(baos);
// Create a new version
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java b/src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java
new file mode 100644
index 0000000000..9fe33ce6c9
--- /dev/null
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java
@@ -0,0 +1,98 @@
+/* ====================================================================
+ 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.poi.hssf.usermodel;
+
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hpsf.SummaryInformation;
+import org.apache.poi.hpsf.PropertySetFactory;
+
+import java.io.FileInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+
+import junit.framework.TestCase;
+
+/**
+ * Old-style setting of POIFS properties doesn't work with POI 3.0.2
+ *
+ * @author Yegor Kozlov
+ */
+public class TestPOIFSProperties extends TestCase{
+ protected String cwd = System.getProperty("HSSF.testdata.path");
+
+ protected String title = "Testing POIFS properties";
+
+ public void testFail() throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "Simple.xls"));
+ POIFSFileSystem fs = new POIFSFileSystem(is);
+ is.close();
+
+ HSSFWorkbook wb = new HSSFWorkbook(fs);
+
+ //set POIFS properties after constructing HSSFWorkbook
+ //(a piece of code that used to work up to POI 3.0.2)
+ SummaryInformation summary1 = (SummaryInformation)PropertySetFactory.create(fs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
+ summary1.setTitle(title);
+ //write the modified property back to POIFS
+ fs.getRoot().getEntry(SummaryInformation.DEFAULT_STREAM_NAME).delete();
+ fs.createDocument(summary1.toInputStream(), SummaryInformation.DEFAULT_STREAM_NAME);
+
+ //save the workbook and read the property
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ wb.write(out);
+ out.close();
+
+ POIFSFileSystem fs2 = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
+ SummaryInformation summary2 = (SummaryInformation)PropertySetFactory.create(fs2.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
+
+ try {
+ //failing assertion
+ assertEquals(title, summary2.getTitle());
+
+ } catch (AssertionError e){
+ assertTrue(true);
+ }
+ }
+
+ public void testOK() throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "Simple.xls"));
+ POIFSFileSystem fs = new POIFSFileSystem(is);
+ is.close();
+
+ //set POIFS properties before constructing HSSFWorkbook
+ SummaryInformation summary1 = (SummaryInformation)PropertySetFactory.create(fs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
+ summary1.setTitle(title);
+
+ fs.getRoot().getEntry(SummaryInformation.DEFAULT_STREAM_NAME).delete();
+ fs.createDocument(summary1.toInputStream(), SummaryInformation.DEFAULT_STREAM_NAME);
+
+ HSSFWorkbook wb = new HSSFWorkbook(fs);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ wb.write(out);
+ out.close();
+
+ //read the property
+ POIFSFileSystem fs2 = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
+ SummaryInformation summary2 = (SummaryInformation)PropertySetFactory.create(fs2.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
+ assertEquals(title, summary2.getTitle());
+
+ }
+}