aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/hpsf
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2017-11-24 01:02:20 +0000
committerAndreas Beeker <kiwiwings@apache.org>2017-11-24 01:02:20 +0000
commitcbfb179254fcf1ec07fb83dea58546b5840d97be (patch)
treefe2101b5cecfd110fd3f4f482cf2d4f92fac8ee3 /src/testcases/org/apache/poi/hpsf
parente0c8416726efa9ca12e0791aa89295c9e7964cde (diff)
downloadpoi-cbfb179254fcf1ec07fb83dea58546b5840d97be.tar.gz
poi-cbfb179254fcf1ec07fb83dea58546b5840d97be.zip
#61809 - Infinite loop in SectionIDMap.get() and .put()
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1816205 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hpsf')
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestBasic.java24
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestWrite.java35
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java18
3 files changed, 56 insertions, 21 deletions
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java b/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java
index e32c6b0d5b..dcb5c67b92 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java
@@ -41,7 +41,7 @@ import org.apache.poi.hpsf.PropertySet;
import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.Section;
import org.apache.poi.hpsf.SummaryInformation;
-import org.apache.poi.hpsf.wellknown.SectionIDMap;
+import org.apache.poi.hpsf.wellknown.PropertyIDMap;
import org.junit.Before;
import org.junit.Test;
@@ -171,13 +171,13 @@ public final class TestBasic {
final SummaryInformation si = (SummaryInformation)PropertySetFactory.create(is);
final List<Section> sections = si.getSections();
final Section s = sections.get(0);
- assertEquals(s.getFormatID(), SectionIDMap.SUMMARY_INFORMATION_ID);
+ assertEquals(s.getFormatID(), SummaryInformation.FORMAT_ID);
assertNotNull(s.getProperties());
assertEquals(17, s.getPropertyCount());
- assertEquals("Titel", s.getProperty(2));
+ assertEquals("Titel", s.getProperty(PropertyIDMap.PID_TITLE));
assertEquals(1764, s.getSize());
}
-
+
@Test
public void bug52117LastPrinted() throws IOException, HPSFException {
File f = samples.getFile("TestBug52117.doc");
@@ -189,4 +189,20 @@ public final class TestBasic {
assertTrue(Filetime.isUndefined(lastPrinted));
assertEquals(1800000000L, editTime);
}
+
+ @Test
+ public void bug61809() throws IOException, HPSFException {
+ InputStream is_si = new ByteArrayInputStream(poiFiles.get(0).getBytes());
+ final SummaryInformation si = (SummaryInformation)PropertySetFactory.create(is_si);
+ final Section s_si = si.getSections().get(0);
+
+ assertEquals("PID_TITLE", s_si.getPIDString(PropertyIDMap.PID_TITLE));
+ assertEquals(PropertyIDMap.UNDEFINED, s_si.getPIDString(4711));
+
+ InputStream is_dsi = new ByteArrayInputStream(poiFiles.get(1).getBytes());
+ final DocumentSummaryInformation dsi = (DocumentSummaryInformation)PropertySetFactory.create(is_dsi);
+ final Section s_dsi = dsi.getSections().get(0);
+
+ assertEquals("PID_MANAGER", s_dsi.getPIDString(PropertyIDMap.PID_MANAGER));
+ }
}
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
index 278ac9421d..24371855f6 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
@@ -42,9 +42,23 @@ import java.util.Locale;
import java.util.Map;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.hpsf.*;
+import org.apache.poi.hpsf.ClassID;
+import org.apache.poi.hpsf.DocumentSummaryInformation;
+import org.apache.poi.hpsf.HPSFException;
+import org.apache.poi.hpsf.IllegalPropertySetDataException;
+import org.apache.poi.hpsf.NoFormatIDException;
+import org.apache.poi.hpsf.NoPropertySetStreamException;
+import org.apache.poi.hpsf.Property;
+import org.apache.poi.hpsf.PropertySet;
+import org.apache.poi.hpsf.PropertySetFactory;
+import org.apache.poi.hpsf.ReadingNotSupportedException;
+import org.apache.poi.hpsf.Section;
+import org.apache.poi.hpsf.SummaryInformation;
+import org.apache.poi.hpsf.UnsupportedVariantTypeException;
+import org.apache.poi.hpsf.Variant;
+import org.apache.poi.hpsf.VariantSupport;
+import org.apache.poi.hpsf.WritingNotSupportedException;
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
-import org.apache.poi.hpsf.wellknown.SectionIDMap;
import org.apache.poi.poifs.eventfilesystem.POIFSReader;
import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent;
import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener;
@@ -72,13 +86,6 @@ public class TestWrite {
private static final String POI_FS = "TestHPSFWritingFunctionality.doc";
- private static final int BYTE_ORDER = 0xfffe;
- private static final int FORMAT = 0x0000;
- private static final int OS_VERSION = 0x00020A04;
- private static final int[] SECTION_COUNT = {1, 2};
- private static final boolean[] IS_SUMMARY_INFORMATION = {true, false};
- private static final boolean[] IS_DOCUMENT_SUMMARY_INFORMATION = {false, true};
-
private static final String IMPROPER_DEFAULT_CHARSET_MESSAGE =
"Your default character set is " + getDefaultCharsetName() +
". However, this testcase must be run in an environment " +
@@ -147,7 +154,7 @@ public class TestWrite {
final POIFSFileSystem poiFs = new POIFSFileSystem();
final PropertySet ps = new PropertySet();
final Section s = ps.getSections().get(0);
- s.setFormatID(SectionIDMap.SUMMARY_INFORMATION_ID);
+ s.setFormatID(SummaryInformation.FORMAT_ID);
final ByteArrayOutputStream psStream = new ByteArrayOutputStream();
ps.write(psStream);
@@ -194,7 +201,7 @@ public class TestWrite {
final PropertySet ps = new PropertySet();
final Section si = new Section();
- si.setFormatID(SectionIDMap.SUMMARY_INFORMATION_ID);
+ si.setFormatID(SummaryInformation.FORMAT_ID);
ps.clearSections();
ps.addSection(si);
@@ -414,7 +421,7 @@ public class TestWrite {
final String TITLE = "This is a sample title";
final PropertySet mps = new PropertySet();
final Section ms = mps.getSections().get(0);
- ms.setFormatID(SectionIDMap.SUMMARY_INFORMATION_ID);
+ ms.setFormatID(SummaryInformation.FORMAT_ID);
final Property p = new Property();
p.setID(PropertyIDMap.PID_TITLE);
p.setType(Variant.VT_LPSTR);
@@ -485,7 +492,7 @@ public class TestWrite {
m.put(Long.valueOf(2), "String 2");
m.put(Long.valueOf(3), "String 3");
s.setDictionary(m);
- s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[0]);
+ s.setFormatID(DocumentSummaryInformation.FORMAT_ID[0]);
int codepage = CodePageUtil.CP_UNICODE;
s.setProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2, codepage);
poiFs.createDocument(ps1.toInputStream(), "Test");
@@ -751,7 +758,7 @@ public class TestWrite {
try {
s.setDictionary(m);
- s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[0]);
+ s.setFormatID(DocumentSummaryInformation.FORMAT_ID[0]);
int codepage = 12345;
s.setProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2,
Integer.valueOf(codepage));
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java b/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java
index af4674e4d1..89c70ac55e 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java
@@ -34,8 +34,20 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.hpsf.*;
-import org.apache.poi.hpsf.wellknown.SectionIDMap;
+import org.apache.poi.hpsf.CustomProperties;
+import org.apache.poi.hpsf.CustomProperty;
+import org.apache.poi.hpsf.DocumentSummaryInformation;
+import org.apache.poi.hpsf.MarkUnsupportedException;
+import org.apache.poi.hpsf.NoPropertySetStreamException;
+import org.apache.poi.hpsf.Property;
+import org.apache.poi.hpsf.PropertySet;
+import org.apache.poi.hpsf.PropertySetFactory;
+import org.apache.poi.hpsf.Section;
+import org.apache.poi.hpsf.SummaryInformation;
+import org.apache.poi.hpsf.UnexpectedPropertySetTypeException;
+import org.apache.poi.hpsf.Variant;
+import org.apache.poi.hpsf.VariantSupport;
+import org.apache.poi.hpsf.WritingNotSupportedException;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.util.IOUtils;
@@ -562,7 +574,7 @@ public class TestWriteWellKnown {
/* Test an empty custom properties set. */
s = new Section();
- s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[1]);
+ s.setFormatID(DocumentSummaryInformation.FORMAT_ID[1]);
// s.setCodepage(CodePageUtil.CP_UNICODE);
dsi.addSection(s);
cps = dsi.getCustomProperties();