You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/09/07 22:19:51 UTC
svn commit: r1701688 [4/7] - in /poi/trunk: ./
src/java/org/apache/poi/hssf/eventusermodel/
src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/usermodel/
src/java/org/apache/poi/poifs/filesystem/
src/java/org/apache/poi/ss/format/ src/jav...
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java Mon Sep 7 20:19:50 2015
@@ -19,9 +19,9 @@ package org.apache.poi.hsmf.datatypes;
import java.math.BigInteger;
import java.util.Calendar;
-import java.util.TimeZone;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LocaleUtil;
/**
* An instance of a {@link MAPIProperty} inside a {@link PropertiesChunk}.
@@ -218,7 +218,7 @@ public class PropertyValue {
long time = LittleEndian.getLong(data);
time = (time / 10 / 1000) - OFFSET;
- Calendar timeC = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+ Calendar timeC = LocaleUtil.getLocaleCalendar();
timeC.setTimeInMillis(time);
return timeC;
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/dev/HSMFDump.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/dev/HSMFDump.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/dev/HSMFDump.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/dev/HSMFDump.java Mon Sep 7 20:19:50 2015
@@ -17,7 +17,7 @@
package org.apache.poi.hsmf.dev;
-import java.io.FileInputStream;
+import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
@@ -27,14 +27,14 @@ import org.apache.poi.hsmf.datatypes.MAP
import org.apache.poi.hsmf.datatypes.PropertiesChunk;
import org.apache.poi.hsmf.datatypes.PropertyValue;
import org.apache.poi.hsmf.parsers.POIFSChunkParser;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
/**
* Dumps out the chunk details, and where possible contents
*/
public class HSMFDump {
- private POIFSFileSystem fs;
- public HSMFDump(POIFSFileSystem fs) {
+ private NPOIFSFileSystem fs;
+ public HSMFDump(NPOIFSFileSystem fs) {
this.fs = fs;
}
@@ -84,9 +84,10 @@ public class HSMFDump {
public static void main(String[] args) throws Exception {
for(String file : args) {
- POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
+ NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(file), true);
HSMFDump dump = new HSMFDump(fs);
dump.dump();
+ fs.close();
}
}
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java Mon Sep 7 20:19:50 2015
@@ -21,7 +21,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Locale;
-import java.util.TimeZone;
import org.apache.poi.POIOLE2TextExtractor;
import org.apache.poi.hsmf.MAPIMessage;
@@ -31,6 +30,7 @@ import org.apache.poi.hsmf.exceptions.Ch
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.StringUtil.StringsIterator;
/**
@@ -51,9 +51,6 @@ public class OutlookTextExtactor extends
public OutlookTextExtactor(DirectoryNode poifsDir) throws IOException {
this(new MAPIMessage(poifsDir));
}
- public OutlookTextExtactor(POIFSFileSystem fs) throws IOException {
- this(new MAPIMessage(fs));
- }
public OutlookTextExtactor(NPOIFSFileSystem fs) throws IOException {
this(new MAPIMessage(fs));
}
@@ -63,11 +60,16 @@ public class OutlookTextExtactor extends
public static void main(String[] args) throws Exception {
for(String filename : args) {
- OutlookTextExtactor extractor = new OutlookTextExtactor(
- new NPOIFSFileSystem(new File(filename))
- );
- System.out.println( extractor.getText() );
- extractor.close();
+ NPOIFSFileSystem poifs = null;
+ OutlookTextExtactor extractor = null;
+ try {
+ poifs = new NPOIFSFileSystem(new File(filename));
+ extractor = new OutlookTextExtactor(poifs);
+ System.out.println( extractor.getText() );
+ } finally {
+ if (extractor != null) extractor.close();
+ if (poifs != null) poifs.close();
+ }
}
}
@@ -120,8 +122,8 @@ public class OutlookTextExtactor extends
// Date - try two ways to find it
try {
// First try via the proper chunk
- SimpleDateFormat f = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss Z");
- f.setTimeZone(TimeZone.getTimeZone("UTC"));
+ SimpleDateFormat f = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss Z", Locale.ROOT);
+ f.setTimeZone(LocaleUtil.getUserTimeZone());
s.append("Date: " + f.format(msg.getMessageDate().getTime()) + "\n");
} catch(ChunkNotFoundException e) {
try {
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java Mon Sep 7 20:19:50 2015
@@ -40,7 +40,7 @@ import org.apache.poi.poifs.filesystem.D
import org.apache.poi.poifs.filesystem.DocumentInputStream;
import org.apache.poi.poifs.filesystem.DocumentNode;
import org.apache.poi.poifs.filesystem.Entry;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
@@ -52,7 +52,7 @@ import org.apache.poi.util.POILogger;
public final class POIFSChunkParser {
private static POILogger logger = POILogFactory.getLogger(POIFSChunkParser.class);
- public static ChunkGroup[] parse(POIFSFileSystem fs) throws IOException {
+ public static ChunkGroup[] parse(NPOIFSFileSystem fs) throws IOException {
return parse(fs.getRoot());
}
public static ChunkGroup[] parse(DirectoryNode node) throws IOException {
@@ -205,12 +205,15 @@ public final class POIFSChunkParser {
if(chunk != null) {
if(entry instanceof DocumentNode) {
+ DocumentInputStream inp = null;
try {
- DocumentInputStream inp = new DocumentInputStream((DocumentNode)entry);
+ inp = new DocumentInputStream((DocumentNode)entry);
chunk.readValue(inp);
grouping.record(chunk);
} catch(IOException e) {
logger.log(POILogger.ERROR, "Error reading from part " + entry.getName() + " - " + e.toString());
+ } finally {
+ if (inp != null) inp.close();
}
} else {
grouping.record(chunk);
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfField.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfField.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfField.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfField.java Mon Sep 7 20:19:50 2015
@@ -19,7 +19,7 @@
package org.apache.poi.hwpf.model;
-import java.text.MessageFormat;
+import java.util.Locale;
import org.apache.poi.util.Internal;
@@ -63,11 +63,9 @@ public class PlexOfField
return fld;
}
- public String toString()
- {
- return MessageFormat.format( "[{0}, {1}) - FLD - 0x{2}; 0x{3}",
- getFcStart(), getFcEnd(),
- Integer.toHexString( 0xff & fld.getBoundaryType() ),
- Integer.toHexString( 0xff & fld.getFlt() ) );
+ public String toString() {
+ String str = String.format(Locale.ROOT, "[%d, %d) - FLD - 0x%x; 0x%x"
+ , getFcStart(), getFcEnd(), fld.getBoundaryType(), fld.getFlt());
+ return str;
}
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java Mon Sep 7 20:19:50 2015
@@ -22,6 +22,7 @@ import java.util.Calendar;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LocaleUtil;
/**
* This class is used to represent a date and time in a Word document.
@@ -39,7 +40,7 @@ public final class DateAndTime
private short _info2;
private static final BitField _months = BitFieldFactory.getInstance(0xf);
private static final BitField _years = BitFieldFactory.getInstance(0x1ff0);
- private static final BitField _weekday = BitFieldFactory.getInstance(0xe000);
+ // private static final BitField _weekday = BitFieldFactory.getInstance(0xe000);
public DateAndTime()
{
@@ -53,8 +54,7 @@ public final class DateAndTime
public Calendar getDate() {
// TODO Discover if the timezone is stored somewhere else or not
- Calendar cal = Calendar.getInstance();
- cal.set(
+ Calendar cal = LocaleUtil.getLocaleCalendar(
_years.getValue(_info2)+1900,
_months.getValue(_info2)-1,
_dom.getValue(_info),
@@ -62,7 +62,6 @@ public final class DateAndTime
_minutes.getValue(_info),
0
);
- cal.set(Calendar.MILLISECOND, 0);
return cal;
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000.java Mon Sep 7 20:19:50 2015
@@ -18,10 +18,19 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Locale;
+
+import org.apache.poi.util.LocaleUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
/**
* Tests that Comment2000 works properly.
@@ -29,7 +38,7 @@ import java.util.Date;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestComment2000 extends TestCase {
+public final class TestComment2000 {
// From a real file
private byte[] data_a = new byte[] {
0x0F, 00, 0xE0-256, 0x2E, 0x9C-256, 00, 00, 00,
@@ -82,22 +91,35 @@ public final class TestComment2000 exten
0x0A, 00, 00, 00
};
- private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+ private static SimpleDateFormat sdf;
+
+ @BeforeClass
+ public static void initDateFormat() {
+ sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.ROOT);
+ sdf.setTimeZone(LocaleUtil.getUserTimeZone());
+ }
+ @Test
public void testRecordType() {
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
assertEquals(12000l, ca.getRecordType());
}
- public void testAuthor() {
+
+ @Test
+ public void testAuthor() {
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
assertEquals("Dumbledore", ca.getAuthor());
assertEquals("D", ca.getAuthorInitials());
}
- public void testText() {
+
+ @Test
+ public void testText() {
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
assertEquals("Yes, they certainly are, aren't they!", ca.getText());
}
- public void testCommentAtom() throws Exception {
+
+ @Test
+ public void testCommentAtom() throws Exception {
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
Comment2000Atom c2a = ca.getComment2000Atom();
@@ -107,7 +129,9 @@ public final class TestComment2000 exten
Date exp_a = sdf.parse("2006-01-24 10:26:15.205");
assertEquals(exp_a, c2a.getDate());
}
- public void testCommentAtomB() throws Exception {
+
+ @Test
+ public void testCommentAtomB() throws Exception {
Comment2000 cb = new Comment2000(data_b, 0, data_b.length);
Comment2000Atom c2b = cb.getComment2000Atom();
@@ -118,7 +142,8 @@ public final class TestComment2000 exten
assertEquals(exp_b, c2b.getDate());
}
- public void testWrite() throws Exception {
+ @Test
+ public void testWrite() throws Exception {
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ca.writeOut(baos);
@@ -131,7 +156,8 @@ public final class TestComment2000 exten
}
// Change a few things
- public void testChange() throws Exception {
+ @Test
+ public void testChange() throws Exception {
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
Comment2000 cb = new Comment2000(data_b, 0, data_b.length);
Comment2000 cn = new Comment2000();
@@ -196,6 +222,7 @@ public final class TestComment2000 exten
/**
* A Comment2000 records with missing commentTextAtom
*/
+ @Test
public void testBug44770() {
byte[] data = {
0x0F, 0x00, (byte)0xE0, 0x2E, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0xBA, 0x0F,
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000Atom.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000Atom.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000Atom.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000Atom.java Mon Sep 7 20:19:50 2015
@@ -18,17 +18,23 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
import java.io.ByteArrayOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Locale;
+
+import org.apache.poi.util.LocaleUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
/**
* Tests that Comment2000Atom works properly.
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestComment2000Atom extends TestCase {
+public final class TestComment2000Atom {
// From a real file
private byte[] data_a = new byte[] {
00, 00, 0xE1-256, 0x2E, 0x1C, 00, 00, 00,
@@ -45,14 +51,22 @@ public final class TestComment2000Atom e
0x0E, 00, 00, 00
};
- private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+ private static SimpleDateFormat sdf;
+
+ @BeforeClass
+ public static void initDateFormat() {
+ sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.ROOT);
+ sdf.setTimeZone(LocaleUtil.getUserTimeZone());
+ }
+ @Test
public void testRecordType() {
Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
assertEquals(12001l, ca.getRecordType());
}
- public void testGetDate() throws Exception {
+ @Test
+ public void testGetDate() throws Exception {
Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
Comment2000Atom cb = new Comment2000Atom(data_b, 0, data_b.length);
@@ -65,7 +79,8 @@ public final class TestComment2000Atom e
assertEquals(exp_b, cb.getDate());
}
- public void testGetNums() {
+ @Test
+ public void testGetNums() {
Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
Comment2000Atom cb = new Comment2000Atom(data_b, 0, data_b.length);
@@ -75,7 +90,8 @@ public final class TestComment2000Atom e
assertEquals(5, cb.getNumber());
}
- public void testGetPos() {
+ @Test
+ public void testGetPos() {
Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
Comment2000Atom cb = new Comment2000Atom(data_b, 0, data_b.length);
@@ -88,7 +104,8 @@ public final class TestComment2000Atom e
assertEquals(0x0E, cb.getYOffset());
}
- public void testWrite() throws Exception {
+ @Test
+ public void testWrite() throws Exception {
Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ca.writeOut(baos);
@@ -101,7 +118,8 @@ public final class TestComment2000Atom e
}
// Create A from scratch
- public void testCreate() throws Exception {
+ @Test
+ public void testCreate() throws Exception {
Comment2000Atom a = new Comment2000Atom();
// Set number, x and y
@@ -125,7 +143,8 @@ public final class TestComment2000Atom e
}
// Try to turn a into b
- public void testChange() throws Exception {
+ @Test
+ public void testChange() throws Exception {
Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
// Change the number
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/util/TestSystemTimeUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/util/TestSystemTimeUtils.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/util/TestSystemTimeUtils.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/util/TestSystemTimeUtils.java Mon Sep 7 20:19:50 2015
@@ -18,17 +18,22 @@
package org.apache.poi.hslf.util;
+import static org.junit.Assert.assertEquals;
+
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Locale;
-import junit.framework.TestCase;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
/**
* Tests that SystemTimeUtils works properly.
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestSystemTimeUtils extends TestCase {
+public final class TestSystemTimeUtils {
// From real files
private byte[] data_a = new byte[] {
0xD6-256, 07, 01, 00,
@@ -43,9 +48,16 @@ public final class TestSystemTimeUtils e
0x0A, 00, 00, 00
};
- private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
+ private static SimpleDateFormat sdf;
+
+ @BeforeClass
+ public static void initDateFormat() {
+ sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.ROOT);
+ sdf.setTimeZone(LocaleUtil.getUserTimeZone());
+ }
- public void testGetDateA() throws Exception {
+ @Test
+ public void testGetDateA() throws Exception {
Date date = SystemTimeUtils.getDate(data_a);
// Is 2006-01-24 (2nd day of week) 10:26:15.205
@@ -54,6 +66,7 @@ public final class TestSystemTimeUtils e
assertEquals(exp, date);
}
+ @Test
public void testGetDateB() throws Exception {
Date date = SystemTimeUtils.getDate(data_b, 8+4);
@@ -63,6 +76,7 @@ public final class TestSystemTimeUtils e
assertEquals(exp, date);
}
+ @Test
public void testWriteDateA() throws Exception {
byte[] out_a = new byte[data_a.length];
Date date = sdf.parse("2006-01-24 10:26:15.205");
@@ -73,6 +87,7 @@ public final class TestSystemTimeUtils e
}
}
+ @Test
public void testWriteDateB() throws Exception {
byte[] out_b = new byte[data_b.length];
// Copy over start and end, ignoring the 16 byte date field in the middle
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java Mon Sep 7 20:19:50 2015
@@ -17,30 +17,28 @@
package org.apache.poi.hsmf;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.apache.poi.hsmf.datatypes.*;
+import org.apache.poi.hsmf.datatypes.TestChunkData;
+import org.apache.poi.hsmf.datatypes.TestSorters;
+import org.apache.poi.hsmf.datatypes.TestTypes;
import org.apache.poi.hsmf.extractor.TestOutlookTextExtractor;
-import org.apache.poi.hsmf.parsers.*;
-
-public final class AllHSMFTests {
- public static Test suite() {
- TestSuite suite = new TestSuite(AllHSMFTests.class.getName());
-
- suite.addTestSuite(TestBasics.class);
- suite.addTestSuite(TestBlankFileRead.class);
- suite.addTestSuite(TestSimpleFileRead.class);
- suite.addTestSuite(TestOutlook30FileRead.class);
- suite.addTestSuite(TestFileWithAttachmentsRead.class);
- suite.addTestSuite(TestChunkData.class);
- suite.addTestSuite(TestTypes.class);
- suite.addTestSuite(TestSorters.class);
- suite.addTestSuite(TestOutlookTextExtractor.class);
- suite.addTestSuite(TestPOIFSChunkParser.class);
- suite.addTestSuite(TestMessageSubmissionChunkY2KRead.class);
- suite.addTestSuite(TestMessageSubmissionChunk.class);
-
- return suite;
- }
+import org.apache.poi.hsmf.parsers.TestPOIFSChunkParser;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TestBasics.class,
+ TestBlankFileRead.class,
+ TestSimpleFileRead.class,
+ TestOutlook30FileRead.class,
+ TestFileWithAttachmentsRead.class,
+ TestChunkData.class,
+ TestTypes.class,
+ TestSorters.class,
+ TestOutlookTextExtractor.class,
+ TestPOIFSChunkParser.class,
+ TestMessageSubmissionChunkY2KRead.class,
+ TestMessageSubmissionChunk.class
+})
+public class AllHSMFTests {
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestFixedSizedProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestFixedSizedProperties.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestFixedSizedProperties.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestFixedSizedProperties.java Mon Sep 7 20:19:50 2015
@@ -17,19 +17,24 @@
package org.apache.poi.hsmf;
+import static org.apache.poi.POITestCase.assertContains;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.POITestCase;
import org.apache.poi.hsmf.datatypes.ChunkBasedPropertyValue;
import org.apache.poi.hsmf.datatypes.Chunks;
import org.apache.poi.hsmf.datatypes.MAPIProperty;
@@ -38,41 +43,58 @@ import org.apache.poi.hsmf.datatypes.Pro
import org.apache.poi.hsmf.datatypes.PropertyValue.TimePropertyValue;
import org.apache.poi.hsmf.dev.HSMFDump;
import org.apache.poi.hsmf.extractor.OutlookTextExtactor;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
/**
* Tests that we can read fixed sized properties, as well as variable
* ones, for example Submission Dates
*/
-public final class TestFixedSizedProperties extends POITestCase {
- protected static final String messageSucceeds = "53784_succeeds.msg";
- protected static final String messageFails = "53784_fails.msg";
- private MAPIMessage mapiMessageSucceeds;
- private MAPIMessage mapiMessageFails;
- private POIFSFileSystem fsMessageSucceeds;
- private POIFSFileSystem fsMessageFails;
- private SimpleDateFormat messageDateFormat;
+public final class TestFixedSizedProperties {
+ private static final String messageSucceeds = "53784_succeeds.msg";
+ private static final String messageFails = "53784_fails.msg";
+ private static MAPIMessage mapiMessageSucceeds;
+ private static MAPIMessage mapiMessageFails;
+ private static NPOIFSFileSystem fsMessageSucceeds;
+ private static NPOIFSFileSystem fsMessageFails;
+ private static SimpleDateFormat messageDateFormat;
+ private static TimeZone userTimeZone;
/**
* Initialize this test, load up the messages.
*/
- public TestFixedSizedProperties() throws Exception {
+ @BeforeClass
+ public static void initMapi() throws Exception {
POIDataSamples samples = POIDataSamples.getHSMFInstance();
- this.mapiMessageSucceeds = new MAPIMessage(
- samples.openResourceAsStream(messageSucceeds));
- this.mapiMessageFails = new MAPIMessage(
- samples.openResourceAsStream(messageFails));
- this.fsMessageSucceeds = new POIFSFileSystem(new FileInputStream(samples.getFile(messageSucceeds)));
- this.fsMessageFails = new POIFSFileSystem(new FileInputStream(samples.getFile(messageFails)));
+ fsMessageSucceeds = new NPOIFSFileSystem(samples.getFile(messageSucceeds));
+ fsMessageFails = new NPOIFSFileSystem(samples.getFile(messageFails));
+
+ mapiMessageSucceeds = new MAPIMessage(fsMessageSucceeds);
+ mapiMessageFails = new MAPIMessage(fsMessageFails);
- messageDateFormat = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss");
- messageDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
+ messageDateFormat = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss", Locale.ROOT);
+ messageDateFormat.setTimeZone(LocaleUtil.TIMEZONE_UTC);
+
+ userTimeZone = LocaleUtil.getUserTimeZone();
+ LocaleUtil.setUserTimeZone(LocaleUtil.TIMEZONE_UTC);
+ }
+
+
+ @AfterClass
+ public static void closeFS() throws Exception {
+ LocaleUtil.setUserTimeZone(userTimeZone);
+ fsMessageSucceeds.close();
+ fsMessageFails.close();
}
/**
* Check we can find a sensible number of properties on a few
* of our test files
*/
+ @Test
public void testPropertiesFound() throws Exception {
Map<MAPIProperty,List<PropertyValue>> props;
@@ -86,6 +108,7 @@ public final class TestFixedSizedPropert
/**
* Check we find properties of a variety of different types
*/
+ @Test
public void testPropertyValueTypes() throws Exception {
Chunks mainChunks = mapiMessageSucceeds.getMainChunks();
@@ -116,30 +139,32 @@ public final class TestFixedSizedPropert
/**
* Test to see if we can read the Date Chunk with OutlookTextExtractor.
- * TODO Work out why the Fri 22nd vs Monday 25th problem is occurring and fix
*/
- public void DISABLEDtestReadMessageDateSucceedsWithOutlookTextExtractor() {
+ @Test
+ // @Ignore("TODO Work out why the Fri 22nd vs Monday 25th problem is occurring and fix")
+ public void testReadMessageDateSucceedsWithOutlookTextExtractor() throws Exception {
OutlookTextExtactor ext = new OutlookTextExtactor(mapiMessageSucceeds);
String text = ext.getText();
-
- assertContains(text, "Date: Fri, 22 Jun 2012 21:32:54\n");
+ assertContains(text, "Date: Fri, 22 Jun 2012 18:32:54 +0000\n");
+ ext.close();
}
/**
* Test to see if we can read the Date Chunk with OutlookTextExtractor.
- * TODO Work out why the Thu 21st vs Monday 25th problem is occurring and fix
*/
- public void DISABLEDtestReadMessageDateFailsWithOutlookTextExtractor() {
+ @Test
+ // @Ignore("TODO Work out why the Thu 21st vs Monday 25th problem is occurring and fix")
+ public void testReadMessageDateFailsWithOutlookTextExtractor() throws Exception {
OutlookTextExtactor ext = new OutlookTextExtactor(mapiMessageFails);
String text = ext.getText();
-
- assertContains(text, "Date: Thu, 21 Jun 2012 17:14:04\n");
+ assertContains(text, "Date: Thu, 21 Jun 2012 14:14:04 +0000\n");
+ ext.close();
}
/**
* Test to see if we can read the Date Chunk with HSMFDump.
- * @throws IOException
*/
+ @Test
public void testReadMessageDateSucceedsWithHSMFDump() throws IOException {
PrintStream stream = new PrintStream(new ByteArrayOutputStream());
HSMFDump dump = new HSMFDump(fsMessageSucceeds);
@@ -148,8 +173,8 @@ public final class TestFixedSizedPropert
/**
* Test to see if we can read the Date Chunk with HSMFDump.
- * @throws Exception
*/
+ @Test
public void testReadMessageDateFailsWithHSMFDump() throws Exception {
PrintStream stream = new PrintStream(new ByteArrayOutputStream());
HSMFDump dump = new HSMFDump(fsMessageFails);
@@ -159,6 +184,7 @@ public final class TestFixedSizedPropert
/**
* Will be based on the ClientSubmit time
*/
+ @Test
public void testClientSubmitTime() throws Exception {
// Check via the message date
Calendar clientSubmitTime = mapiMessageSucceeds.getMessageDate();
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/extractor/TestOutlookTextExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/extractor/TestOutlookTextExtractor.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/extractor/TestOutlookTextExtractor.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/extractor/TestOutlookTextExtractor.java Mon Sep 7 20:19:50 2015
@@ -17,33 +17,47 @@
package org.apache.poi.hsmf.extractor;
+import static org.apache.poi.POITestCase.assertContains;
+import static org.apache.poi.POITestCase.assertNotContained;
+import static org.junit.Assert.assertEquals;
+
import java.io.FileInputStream;
-import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
-import java.util.GregorianCalendar;
+import java.util.Locale;
import java.util.TimeZone;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.POITestCase;
import org.apache.poi.hsmf.MAPIMessage;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
/**
* Tests to verify that the text extractor works
*/
-public final class TestOutlookTextExtractor extends POITestCase {
- private POIDataSamples samples;
-
- public TestOutlookTextExtractor() throws IOException {
- samples = POIDataSamples.getHSMFInstance();
- }
+public final class TestOutlookTextExtractor {
+ private POIDataSamples samples = POIDataSamples.getHSMFInstance();
+ private static TimeZone userTZ;
+
+ @BeforeClass
+ public static void initTimeZone() {
+ userTZ = LocaleUtil.getUserTimeZone();
+ LocaleUtil.setUserTimeZone(LocaleUtil.TIMEZONE_UTC);
+ }
+
+ @AfterClass
+ public static void resetTimeZone() {
+ LocaleUtil.setUserTimeZone(userTZ);
+ }
+
+ @Test
public void testQuick() throws Exception {
- POIFSFileSystem simple = new POIFSFileSystem(
- new FileInputStream(samples.getFile("quick.msg"))
- );
- MAPIMessage msg = new MAPIMessage(simple);
+ NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
+ MAPIMessage msg = new MAPIMessage(poifs);
OutlookTextExtactor ext = new OutlookTextExtactor(msg);
String text = ext.getText();
@@ -54,20 +68,21 @@ public final class TestOutlookTextExtrac
assertEquals(-1, text.indexOf("BCC:"));
assertEquals(-1, text.indexOf("Attachment:"));
assertContains(text, "Subject: Test the content transformer\n");
- Calendar cal = new GregorianCalendar(2007, 5, 14, 9, 42, 55);
- SimpleDateFormat f = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss Z");
- f.setTimeZone(TimeZone.getTimeZone("UTC"));
+ Calendar cal = LocaleUtil.getLocaleCalendar(2007, 5, 14, 9, 42, 55);
+ SimpleDateFormat f = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss Z", Locale.ROOT);
+ f.setTimeZone(LocaleUtil.getUserTimeZone());
String dateText = f.format(cal.getTime());
assertContains(text, "Date: " + dateText + "\n");
assertContains(text, "The quick brown fox jumps over the lazy dog");
ext.close();
+ poifs.close();
}
+ @Test
public void testSimple() throws Exception {
- MAPIMessage msg = new MAPIMessage(new POIFSFileSystem(
- new FileInputStream(samples.getFile("simple_test_msg.msg"))
- ));
+ NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("simple_test_msg.msg"), true);
+ MAPIMessage msg = new MAPIMessage(poifs);
OutlookTextExtactor ext = new OutlookTextExtactor(msg);
String text = ext.getText();
@@ -81,25 +96,30 @@ public final class TestOutlookTextExtrac
assertContains(text, "This is a test message.");
ext.close();
+ poifs.close();
}
+ @Test
public void testConstructors() throws Exception {
- OutlookTextExtactor ext = new OutlookTextExtactor(new FileInputStream(
- samples.getFile("simple_test_msg.msg")));
+ FileInputStream fis = new FileInputStream(samples.getFile("simple_test_msg.msg"));
+ OutlookTextExtactor ext = new OutlookTextExtactor(fis);
String inp = ext.getText();
ext.close();
+ fis.close();
- ext = new OutlookTextExtactor(new POIFSFileSystem(new FileInputStream(
- samples.getFile("simple_test_msg.msg"))));
- String poifs = ext.getText();
+ NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("simple_test_msg.msg"), true);
+ ext = new OutlookTextExtactor(poifs);
+ String poifsTxt = ext.getText();
ext.close();
+ poifs.close();
- ext = new OutlookTextExtactor(new MAPIMessage(new FileInputStream(
- samples.getFile("simple_test_msg.msg"))));
+ fis = new FileInputStream(samples.getFile("simple_test_msg.msg"));
+ ext = new OutlookTextExtactor(new MAPIMessage(fis));
String mapi = ext.getText();
ext.close();
+ fis.close();
- assertEquals(inp, poifs);
+ assertEquals(inp, poifsTxt);
assertEquals(inp, mapi);
}
@@ -107,6 +127,7 @@ public final class TestOutlookTextExtrac
* Test that we correctly handle multiple To+CC+BCC
* recipients in an email we sent.
*/
+ @Test
public void testSentWithMulipleRecipients() throws Exception {
// To: 'Ashutosh Dandavate' <as...@alfresco.com>,
// 'Paul Holmes-Higgin' <pa...@alfresco.com>,
@@ -120,9 +141,8 @@ public final class TestOutlookTextExtrac
"example_sent_regular.msg", "example_sent_unicode.msg"
};
for(String file : files) {
- MAPIMessage msg = new MAPIMessage(new POIFSFileSystem(
- new FileInputStream(samples.getFile(file))
- ));
+ NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile(file), true);
+ MAPIMessage msg = new MAPIMessage(poifs);
OutlookTextExtactor ext = new OutlookTextExtactor(msg);
String text = ext.getText();
@@ -139,6 +159,7 @@ public final class TestOutlookTextExtrac
assertContains(text, "The quick brown fox jumps over the lazy dog");
ext.close();
+ poifs.close();
}
}
@@ -146,6 +167,7 @@ public final class TestOutlookTextExtrac
* Test that we correctly handle multiple To+CC
* recipients in an email we received.
*/
+ @Test
public void testReceivedWithMultipleRecipients() throws Exception {
// To: 'Ashutosh Dandavate' <as...@alfresco.com>,
// 'Paul Holmes-Higgin' <pa...@alfresco.com>,
@@ -159,9 +181,9 @@ public final class TestOutlookTextExtrac
"example_received_regular.msg", "example_received_unicode.msg"
};
for(String file : files) {
- MAPIMessage msg = new MAPIMessage(new POIFSFileSystem(
- new FileInputStream(samples.getFile(file))
- ));
+ NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile(file), true);
+ MAPIMessage msg = new MAPIMessage(poifs);
+
OutlookTextExtactor ext = new OutlookTextExtactor(msg);
String text = ext.getText();
@@ -177,6 +199,7 @@ public final class TestOutlookTextExtrac
assertContains(text, "The quick brown fox jumps over the lazy dog");
ext.close();
+ poifs.close();
}
}
@@ -184,10 +207,8 @@ public final class TestOutlookTextExtrac
* See also {@link org.apache.poi.extractor.TestExtractorFactory#testEmbeded()}
*/
public void testWithAttachments() throws Exception {
- POIFSFileSystem simple = new POIFSFileSystem(
- new FileInputStream(samples.getFile("attachment_test_msg.msg"))
- );
- MAPIMessage msg = new MAPIMessage(simple);
+ NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("attachment_test_msg.msg"), true);
+ MAPIMessage msg = new MAPIMessage(poifs);
OutlookTextExtactor ext = new OutlookTextExtactor(msg);
// Check the normal bits
@@ -207,13 +228,12 @@ public final class TestOutlookTextExtrac
// TestExtractorFactory
ext.close();
+ poifs.close();
}
public void testWithAttachedMessage() throws Exception {
- POIFSFileSystem simple = new POIFSFileSystem(
- new FileInputStream(samples.getFile("58214_with_attachment.msg"))
- );
- MAPIMessage msg = new MAPIMessage(simple);
+ NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("58214_with_attachment.msg"), true);
+ MAPIMessage msg = new MAPIMessage(poifs);
OutlookTextExtactor ext = new OutlookTextExtactor(msg);
String text = ext.getText();
@@ -226,13 +246,12 @@ public final class TestOutlookTextExtrac
assertNotContained(text, "Lorem ipsum dolor sit");
ext.close();
+ poifs.close();
}
public void testEncodings() throws Exception {
- POIFSFileSystem simple = new POIFSFileSystem(
- new FileInputStream(samples.getFile("chinese-traditional.msg"))
- );
- MAPIMessage msg = new MAPIMessage(simple);
+ NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("chinese-traditional.msg"), true);
+ MAPIMessage msg = new MAPIMessage(poifs);
OutlookTextExtactor ext = new OutlookTextExtactor(msg);
String text = ext.getText();
@@ -245,5 +264,6 @@ public final class TestOutlookTextExtrac
assertContains(text, "( MSG \u683c\u5f0f\u6e2c\u8a66 )");
ext.close();
+ poifs.close();
}
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java Mon Sep 7 20:19:50 2015
@@ -17,13 +17,16 @@
package org.apache.poi.hsmf.parsers;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.IOException;
-import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
+import org.apache.poi.POIDataSamples;
import org.apache.poi.hsmf.MAPIMessage;
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
import org.apache.poi.hsmf.datatypes.ChunkGroup;
@@ -35,25 +38,19 @@ import org.apache.poi.hsmf.datatypes.Rec
import org.apache.poi.hsmf.datatypes.StringChunk;
import org.apache.poi.hsmf.datatypes.Types;
import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.POIDataSamples;
-
-import junit.framework.TestCase;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
/**
* Tests to verify that the chunk parser works properly
*/
-public final class TestPOIFSChunkParser extends TestCase {
- private POIDataSamples samples;
+public final class TestPOIFSChunkParser {
+ private POIDataSamples samples = POIDataSamples.getHSMFInstance();
- public TestPOIFSChunkParser() throws IOException {
- samples = POIDataSamples.getHSMFInstance();
- }
-
- public void testFindsCore() throws IOException {
- POIFSFileSystem simple = new POIFSFileSystem(
- new FileInputStream(samples.getFile("quick.msg"))
- );
+ @Test
+ public void testFindsCore() throws Exception {
+ NPOIFSFileSystem simple = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
// Check a few core things are present
simple.getRoot().getEntry(
@@ -65,29 +62,20 @@ public final class TestPOIFSChunkParser
// Now load the file
MAPIMessage msg = new MAPIMessage(simple);
- try {
- assertEquals("Kevin Roast", msg.getDisplayTo());
- assertEquals("Kevin Roast", msg.getDisplayFrom());
- assertEquals("Test the content transformer", msg.getSubject());
- } catch(ChunkNotFoundException e) {
- fail();
- }
+ assertEquals("Kevin Roast", msg.getDisplayTo());
+ assertEquals("Kevin Roast", msg.getDisplayFrom());
+ assertEquals("Test the content transformer", msg.getSubject());
// Check date too
- try {
- SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
- Calendar c = msg.getMessageDate();
- assertEquals( "2007-06-14 09:42:55", f.format(c.getTime()) );
- } catch(ChunkNotFoundException e) {
- fail();
- }
+ Calendar calExp = LocaleUtil.getLocaleCalendar(2007,5,14,9,42,55);
+ Calendar calAct = msg.getMessageDate();
+ assertEquals( calExp, calAct );
+
+ simple.close();
}
public void testFindsRecips() throws IOException, ChunkNotFoundException {
- POIFSFileSystem simple = new POIFSFileSystem(
- new FileInputStream(samples.getFile("quick.msg"))
- );
+ NPOIFSFileSystem simple = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
simple.getRoot().getEntry("__recip_version1.0_#00000000");
@@ -121,11 +109,12 @@ public final class TestPOIFSChunkParser
assertEquals("kevin.roast@alfresco.org", msg.getRecipientDetailsChunks()[0].recipientSMTPChunk.getValue());
assertEquals("/O=HOSTEDSERVICE2/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=Kevin.roast@ben",
msg.getRecipientDetailsChunks()[0].recipientEmailChunk.getValue());
+ simple.close();
+
// Now look at another message
- msg = new MAPIMessage(new POIFSFileSystem(
- new FileInputStream(samples.getFile("simple_test_msg.msg"))
- ));
+ simple = new NPOIFSFileSystem(samples.getFile("simple_test_msg.msg"), true);
+ msg = new MAPIMessage(simple);
assertNotNull(msg.getRecipientDetailsChunks());
assertEquals(1, msg.getRecipientDetailsChunks().length);
@@ -134,12 +123,12 @@ public final class TestPOIFSChunkParser
assertEquals(null, msg.getRecipientDetailsChunks()[0].recipientNameChunk);
assertEquals("travis@overwrittenstack.com", msg.getRecipientDetailsChunks()[0].recipientEmailChunk.getValue());
assertEquals("travis@overwrittenstack.com", msg.getRecipientEmailAddress());
+
+ simple.close();
}
public void testFindsMultipleRecipients() throws IOException, ChunkNotFoundException {
- POIFSFileSystem multiple = new POIFSFileSystem(
- new FileInputStream(samples.getFile("example_received_unicode.msg"))
- );
+ NPOIFSFileSystem multiple = new NPOIFSFileSystem(samples.getFile("example_received_unicode.msg"), true);
multiple.getRoot().getEntry("__recip_version1.0_#00000000");
multiple.getRoot().getEntry("__recip_version1.0_#00000001");
@@ -225,12 +214,12 @@ public final class TestPOIFSChunkParser
assertEquals("nickb@alfresco.com", msg.getRecipientEmailAddressList()[3]);
assertEquals("nick.burch@alfresco.com", msg.getRecipientEmailAddressList()[4]);
assertEquals("roy.wetherall@alfresco.com", msg.getRecipientEmailAddressList()[5]);
+
+ multiple.close();
}
public void testFindsNameId() throws IOException {
- POIFSFileSystem simple = new POIFSFileSystem(
- new FileInputStream(samples.getFile("quick.msg"))
- );
+ NPOIFSFileSystem simple = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
simple.getRoot().getEntry("__nameid_version1.0");
@@ -247,15 +236,13 @@ public final class TestPOIFSChunkParser
MAPIMessage msg = new MAPIMessage(simple);
assertNotNull(msg.getNameIdChunks());
assertEquals(10, msg.getNameIdChunks().getAll().length);
+
+ simple.close();
}
- public void testFindsAttachments() throws IOException {
- POIFSFileSystem with = new POIFSFileSystem(
- new FileInputStream(samples.getFile("attachment_test_msg.msg"))
- );
- POIFSFileSystem without = new POIFSFileSystem(
- new FileInputStream(samples.getFile("quick.msg"))
- );
+ public void testFindsAttachments() throws Exception {
+ NPOIFSFileSystem with = new NPOIFSFileSystem(samples.getFile("attachment_test_msg.msg"), true);
+ NPOIFSFileSystem without = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
AttachmentChunks attachment;
@@ -284,15 +271,8 @@ public final class TestPOIFSChunkParser
// Check raw details on one without
- try {
- without.getRoot().getEntry("__attach_version1.0_#00000000");
- fail();
- } catch(FileNotFoundException e) {}
- try {
- without.getRoot().getEntry("__attach_version1.0_#00000001");
- fail();
- } catch(FileNotFoundException e) {}
-
+ assertFalse(without.getRoot().hasEntry("__attach_version1.0_#00000000"));
+ assertFalse(without.getRoot().hasEntry("__attach_version1.0_#00000001"));
// One with, from the top
MAPIMessage msgWith = new MAPIMessage(with);
@@ -309,14 +289,9 @@ public final class TestPOIFSChunkParser
assertEquals(89, attachment.attachData.getValue().length);
// Plus check core details are there
- try {
- assertEquals("'nicolas1.23456@free.fr'", msgWith.getDisplayTo());
- assertEquals("Nicolas1 23456", msgWith.getDisplayFrom());
- assertEquals("test pi\u00e8ce jointe 1", msgWith.getSubject());
- } catch(ChunkNotFoundException e) {
- fail();
- }
-
+ assertEquals("'nicolas1.23456@free.fr'", msgWith.getDisplayTo());
+ assertEquals("Nicolas1 23456", msgWith.getDisplayFrom());
+ assertEquals("test pi\u00e8ce jointe 1", msgWith.getSubject());
// One without, from the top
MAPIMessage msgWithout = new MAPIMessage(without);
@@ -325,13 +300,12 @@ public final class TestPOIFSChunkParser
assertEquals(0, msgWithout.getAttachmentFiles().length);
// But has core details
- try {
- assertEquals("Kevin Roast", msgWithout.getDisplayTo());
- assertEquals("Kevin Roast", msgWithout.getDisplayFrom());
- assertEquals("Test the content transformer", msgWithout.getSubject());
- } catch(ChunkNotFoundException e) {
- fail();
- }
+ assertEquals("Kevin Roast", msgWithout.getDisplayTo());
+ assertEquals("Kevin Roast", msgWithout.getDisplayFrom());
+ assertEquals("Test the content transformer", msgWithout.getSubject());
+
+ without.close();
+ with.close();
}
/**
@@ -340,13 +314,13 @@ public final class TestPOIFSChunkParser
* such as "Olk10SideProps_0001"
*/
public void testOlk10SideProps() throws Exception {
- POIFSFileSystem poifs = new POIFSFileSystem(
- new FileInputStream(samples.getFile("51873.msg"))
- );
+ NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("51873.msg"), true);
MAPIMessage msg = new MAPIMessage(poifs);
// Check core details came through
assertEquals("bubba@bubbasmith.com", msg.getDisplayTo());
assertEquals("Test with Olk10SideProps_ Chunk", msg.getSubject());
+
+ poifs.close();
}
}
Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java Mon Sep 7 20:19:50 2015
@@ -38,6 +38,7 @@ import java.io.UnsupportedEncodingExcept
import java.nio.charset.Charset;
import java.util.Date;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
import org.apache.poi.POIDataSamples;
@@ -117,8 +118,8 @@ public class TestWrite
*
* @exception IOException if an I/O exception occurs
*/
- @Test
- public void withoutAFormatID() throws IOException
+ @Test(expected=NoFormatIDException.class)
+ public void withoutAFormatID() throws Exception
{
final File filename = TempFile.createTempFile(POI_FS, ".doc");
@@ -131,8 +132,7 @@ public class TestWrite
ps.addSection(new MutableSection());
/* Write it to a POIFS and the latter to disk: */
- try
- {
+ try {
final ByteArrayOutputStream psStream = new ByteArrayOutputStream();
ps.write(psStream);
psStream.close();
@@ -140,15 +140,8 @@ public class TestWrite
poiFs.createDocument(new ByteArrayInputStream(streamData),
SummaryInformation.DEFAULT_STREAM_NAME);
poiFs.writeFilesystem(out);
- out.close();
- fail("Should have thrown a NoFormatIDException.");
- }
- catch (Exception ex)
- {
- assertTrue(ex instanceof NoFormatIDException);
- }
- finally
- {
+ } finally {
+ poiFs.close();
out.close();
}
}
@@ -185,6 +178,7 @@ public class TestWrite
poiFs.createDocument(new ByteArrayInputStream(streamData),
SummaryInformation.DEFAULT_STREAM_NAME);
poiFs.writeFilesystem(out);
+ poiFs.close();
out.close();
/* Read the POIFS: */
@@ -236,6 +230,7 @@ public class TestWrite
poiFs.createDocument(ps.toInputStream(),
SummaryInformation.DEFAULT_STREAM_NAME);
poiFs.writeFilesystem(out);
+ poiFs.close();
out.close();
/* Read the POIFS: */
@@ -317,6 +312,7 @@ public class TestWrite
poiFs.createDocument(ps.toInputStream(), STREAM_NAME);
poiFs.writeFilesystem(out);
+ poiFs.close();
out.close();
/* Read the POIFS: */
@@ -755,6 +751,7 @@ public class TestWrite
psf1[i].getName());
poiFs.writeFilesystem(out);
}
+ poiFs.close();
out.close();
@@ -805,6 +802,7 @@ public class TestWrite
Integer.valueOf(codepage));
poiFs.createDocument(ps1.toInputStream(), "Test");
poiFs.writeFilesystem(out);
+ poiFs.close();
out.close();
/* Read back: */
@@ -1010,7 +1008,7 @@ public class TestWrite
// or via sun.misc.Cleaner, but this is regarded unsafe
// http://stackoverflow.com/questions/2972986
// http://bugs.java.com/view_bug.do?bug_id=4724038
- Assume.assumeFalse(System.getProperty("os.name").toLowerCase().contains("win"));
+ Assume.assumeFalse(System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win"));
throw e;
}
}
@@ -1022,7 +1020,7 @@ public class TestWrite
* @throws IOException
* @throws HPSFException
*/
- @Test
+ @Test(expected=IllegalPropertySetDataException.class)
public void dictionaryWithInvalidCodepage() throws IOException, HPSFException
{
final File copy = TempFile.createTempFile("Test-HPSF", "ole2");
@@ -1039,8 +1037,7 @@ public class TestWrite
m.put(Long.valueOf(2), "String 2");
m.put(Long.valueOf(3), "String 3");
- try
- {
+ try {
s.setDictionary(m);
s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[0]);
int codepage = 12345;
@@ -1048,13 +1045,9 @@ public class TestWrite
Integer.valueOf(codepage));
poiFs.createDocument(ps1.toInputStream(), "Test");
poiFs.writeFilesystem(out);
+ } finally {
+ poiFs.close();
out.close();
- fail("This testcase did not detect the invalid codepage value.");
- }
- catch (IllegalPropertySetDataException ex)
- {
- out.close();
- assertTrue(true);
}
}
@@ -1069,7 +1062,7 @@ public class TestWrite
{
final String charSetName = System.getProperty("file.encoding");
final Charset charSet = Charset.forName(charSetName);
- return charSet.displayName();
+ return charSet.displayName(Locale.ROOT);
}
Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java Mon Sep 7 20:19:50 2015
@@ -17,6 +17,12 @@
package org.apache.poi.hpsf.basic;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
@@ -26,45 +32,47 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.Calendar;
import java.util.Date;
-import java.util.GregorianCalendar;
import java.util.HashMap;
-import java.util.Locale;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.apache.poi.POIDataSamples;
-import org.apache.poi.hpsf.*;
+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.MutableProperty;
+import org.apache.poi.hpsf.MutableSection;
+import org.apache.poi.hpsf.NoPropertySetStreamException;
+import org.apache.poi.hpsf.PropertySet;
+import org.apache.poi.hpsf.PropertySetFactory;
+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.hpsf.wellknown.SectionIDMap;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
-import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.TempFile;
+import org.junit.BeforeClass;
+import org.junit.Test;
/**
* <p>Tests HPSF's high-level writing functionality for the well-known property
* set "SummaryInformation" and "DocumentSummaryInformation".</p>
- *
- * @author Rainer Klute
- * <a href="mailto:klute@rainer-klute.de">klute@rainer-klute.de</a>
*/
-public class TestWriteWellKnown extends TestCase {
+public class TestWriteWellKnown {
private static final String POI_FS = "TestWriteWellKnown.doc";
-
- /**
- * @see TestCase#setUp()
- */
- @Override
- public void setUp()
- {
+ @BeforeClass
+ public static void setUp() {
VariantSupport.setLogUnsupportedTypes(false);
}
-
-
/**
* <p>This test method checks whether DocumentSummary information streams
* can be read. This is done by opening all "Test*" files in the 'poifs' directrory
@@ -72,6 +80,7 @@ public class TestWriteWellKnown extends
* the document summary information stream in the root directory and calling
* its get... methods.</p>
*/
+ @Test
public void testReadDocumentSummaryInformation()
throws FileNotFoundException, IOException,
NoPropertySetStreamException, MarkUnsupportedException,
@@ -88,36 +97,18 @@ public class TestWriteWellKnown extends
}
});
- for (int i = 0; i < docs.length; i++)
- {
+ for (final File doc : docs) {
+ NPOIFSFileSystem poifs = null;
try {
- final File doc = docs[i];
-
/* Read a test document <em>doc</em> into a POI filesystem. */
- final POIFSFileSystem poifs = new POIFSFileSystem(new FileInputStream(doc));
+ poifs = new NPOIFSFileSystem(doc, true);
final DirectoryEntry dir = poifs.getRoot();
- DocumentEntry dsiEntry = null;
- try
- {
- dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
- }
- catch (FileNotFoundException ex)
- {
- /*
- * A missing document summary information stream is not an error
- * and therefore silently ignored here.
- */
- }
-
/*
* If there is a document summry information stream, read it from
* the POI filesystem.
*/
- if (dsiEntry != null)
- {
- final DocumentInputStream dis = new DocumentInputStream(dsiEntry);
- final PropertySet ps = new PropertySet(dis);
- final DocumentSummaryInformation dsi = new DocumentSummaryInformation(ps);
+ if (dir.hasEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)) {
+ final DocumentSummaryInformation dsi = getDocumentSummaryInformation(poifs);
/* Execute the get... methods. */
dsi.getByteCount();
@@ -139,12 +130,72 @@ public class TestWriteWellKnown extends
dsi.getSlideCount();
}
} catch (Exception e) {
- throw new IOException("While handling file " + docs[i], e);
+ throw new IOException("While handling file " + doc, e);
+ } finally {
+ if (poifs != null) poifs.close();
}
}
}
-
+ static final String P_APPLICATION_NAME = "ApplicationName";
+ static final String P_AUTHOR = "Author";
+ static final int P_CHAR_COUNT = 4712;
+ static final String P_COMMENTS = "Comments";
+ static final Date P_CREATE_DATE_TIME;
+ static final long P_EDIT_TIME = 4713 * 1000 * 10;
+ static final String P_KEYWORDS = "Keywords";
+ static final String P_LAST_AUTHOR = "LastAuthor";
+ static final Date P_LAST_PRINTED;
+ static final Date P_LAST_SAVE_DATE_TIME;
+ static final int P_PAGE_COUNT = 4714;
+ static final String P_REV_NUMBER = "RevNumber";
+ static final int P_SECURITY = 1;
+ static final String P_SUBJECT = "Subject";
+ static final String P_TEMPLATE = "Template";
+ // FIXME (byte array properties not yet implemented): static final byte[] P_THUMBNAIL = new byte[123];
+ static final String P_TITLE = "Title";
+ static final int P_WORD_COUNT = 4715;
+
+ static final int P_BYTE_COUNT = 4716;
+ static final String P_CATEGORY = "Category";
+ static final String P_COMPANY = "Company";
+ // FIXME (byte array properties not yet implemented): static final byte[] P_DOCPARTS = new byte[123];
+ // FIXME (byte array properties not yet implemented): static final byte[] P_HEADING_PAIR = new byte[123];
+ static final int P_HIDDEN_COUNT = 4717;
+ static final int P_LINE_COUNT = 4718;
+ static final boolean P_LINKS_DIRTY = true;
+ static final String P_MANAGER = "Manager";
+ static final int P_MM_CLIP_COUNT = 4719;
+ static final int P_NOTE_COUNT = 4720;
+ static final int P_PAR_COUNT = 4721;
+ static final String P_PRESENTATION_FORMAT = "PresentationFormat";
+ static final boolean P_SCALE = false;
+ static final int P_SLIDE_COUNT = 4722;
+ static final Date now = new Date();
+
+ static final Integer POSITIVE_INTEGER = new Integer(2222);
+ static final Long POSITIVE_LONG = new Long(3333);
+ static final Double POSITIVE_DOUBLE = new Double(4444);
+ static final Integer NEGATIVE_INTEGER = new Integer(2222);
+ static final Long NEGATIVE_LONG = new Long(3333);
+ static final Double NEGATIVE_DOUBLE = new Double(4444);
+
+ static final Integer MAX_INTEGER = new Integer(Integer.MAX_VALUE);
+ static final Integer MIN_INTEGER = new Integer(Integer.MIN_VALUE);
+ static final Long MAX_LONG = new Long(Long.MAX_VALUE);
+ static final Long MIN_LONG = new Long(Long.MIN_VALUE);
+ static final Double MAX_DOUBLE = new Double(Double.MAX_VALUE);
+ static final Double MIN_DOUBLE = new Double(Double.MIN_VALUE);
+
+ static {
+ Calendar cal = LocaleUtil.getLocaleCalendar(2000, 6, 6, 6, 6, 6);
+ P_CREATE_DATE_TIME = cal.getTime();
+ cal.set(2001, 7, 7, 7, 7, 7);
+ P_LAST_PRINTED = cal.getTime();
+ cal.set(2002, 8, 8, 8, 8, 8);
+ P_LAST_SAVE_DATE_TIME = cal.getTime();
+ }
+
/**
* <p>This test method test the writing of properties in the well-known
* property set streams "SummaryInformation" and
@@ -192,19 +243,35 @@ public class TestWriteWellKnown extends
* @throws UnexpectedPropertySetTypeException
* @throws WritingNotSupportedException
*/
- public void testWriteWellKnown() throws IOException,
- NoPropertySetStreamException, MarkUnsupportedException,
- UnexpectedPropertySetTypeException, WritingNotSupportedException
- {
+ @Test
+ public void testWriteWellKnown() throws Exception {
POIDataSamples _samples = POIDataSamples.getHPSFInstance();
- final File dataDir = _samples.getFile("");
- final File doc1 = new File(dataDir, POI_FS);
-
+
+ final File doc1 = TempFile.createTempFile("POI_HPSF_Test1.", ".tmp");
+ final File doc2 = TempFile.createTempFile("POI_HPSF_Test2.", ".tmp");
+ final File doc3 = TempFile.createTempFile("POI_HPSF_Test3.", ".tmp");
+
+ FileInputStream fis = new FileInputStream(_samples.getFile(POI_FS));
+ FileOutputStream fos = new FileOutputStream(doc1);
+ IOUtils.copy(fis, fos);
+ fos.close();
+ fis.close();
+
+ CustomProperties cps1 = write1stFile(doc1, doc2);
+ CustomProperties cps2 = write2ndFile(doc2, doc3);
+ write3rdFile(doc3, null);
+
+ assertEquals(cps1, cps2);
+ }
+
+ /*
+ * Write all properties supported by HPSF to the summary information
+ * (e.g. author, edit date, application name) and to the document
+ * summary information (e.g. company, manager).
+ */
+ private static CustomProperties write1stFile(File fileIn, File fileOut) throws Exception {
/* Read a test document <em>doc1</em> into a POI filesystem. */
- POIFSFileSystem poifs = new POIFSFileSystem(new FileInputStream(doc1));
- DirectoryEntry dir = poifs.getRoot();
- DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
- DocumentEntry dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
+ NPOIFSFileSystem poifs = new NPOIFSFileSystem(fileIn, false);
/*
* Read the summary information stream and the document summary
@@ -216,76 +283,8 @@ public class TestWriteWellKnown extends
* explicitly (overwriting the former contents). Then the POI filesystem
* should be saved to a file.
*/
- DocumentInputStream dis = new DocumentInputStream(siEntry);
- PropertySet ps = new PropertySet(dis);
- SummaryInformation si = new SummaryInformation(ps);
- dis = new DocumentInputStream(dsiEntry);
- ps = new PropertySet(dis);
- DocumentSummaryInformation dsi = new DocumentSummaryInformation(ps);
-
- /*
- * Write all properties supported by HPSF to the summary information
- * (e.g. author, edit date, application name) and to the document
- * summary information (e.g. company, manager).
- */
- Calendar cal = new GregorianCalendar(Locale.ROOT);
- cal.set(2000, 6, 6, 6, 6, 6);
- final long time1 = cal.getTimeInMillis();
- cal.set(2001, 7, 7, 7, 7, 7);
- final long time2 = cal.getTimeInMillis();
- cal.set(2002, 8, 8, 8, 8, 8);
- final long time3 = cal.getTimeInMillis();
-
- int nr = 4711;
- final String P_APPLICATION_NAME = "ApplicationName";
- final String P_AUTHOR = "Author";
- final int P_CHAR_COUNT = ++nr;
- final String P_COMMENTS = "Comments";
- final Date P_CREATE_DATE_TIME = new Date(time1);
- final long P_EDIT_TIME = ++nr * 1000 * 10;
- final String P_KEYWORDS = "Keywords";
- final String P_LAST_AUTHOR = "LastAuthor";
- final Date P_LAST_PRINTED = new Date(time2);
- final Date P_LAST_SAVE_DATE_TIME = new Date(time3);
- final int P_PAGE_COUNT = ++nr;
- final String P_REV_NUMBER = "RevNumber";
- final int P_SECURITY = 1;
- final String P_SUBJECT = "Subject";
- final String P_TEMPLATE = "Template";
- // FIXME (byte array properties not yet implemented): final byte[] P_THUMBNAIL = new byte[123];
- final String P_TITLE = "Title";
- final int P_WORD_COUNT = ++nr;
-
- final int P_BYTE_COUNT = ++nr;
- final String P_CATEGORY = "Category";
- final String P_COMPANY = "Company";
- // FIXME (byte array properties not yet implemented): final byte[] P_DOCPARTS = new byte[123];
- // FIXME (byte array properties not yet implemented): final byte[] P_HEADING_PAIR = new byte[123];
- final int P_HIDDEN_COUNT = ++nr;
- final int P_LINE_COUNT = ++nr;
- final boolean P_LINKS_DIRTY = true;
- final String P_MANAGER = "Manager";
- final int P_MM_CLIP_COUNT = ++nr;
- final int P_NOTE_COUNT = ++nr;
- final int P_PAR_COUNT = ++nr;
- final String P_PRESENTATION_FORMAT = "PresentationFormat";
- final boolean P_SCALE = false;
- final int P_SLIDE_COUNT = ++nr;
- final Date now = new Date();
-
- final Integer POSITIVE_INTEGER = new Integer(2222);
- final Long POSITIVE_LONG = new Long(3333);
- final Double POSITIVE_DOUBLE = new Double(4444);
- final Integer NEGATIVE_INTEGER = new Integer(2222);
- final Long NEGATIVE_LONG = new Long(3333);
- final Double NEGATIVE_DOUBLE = new Double(4444);
-
- final Integer MAX_INTEGER = new Integer(Integer.MAX_VALUE);
- final Integer MIN_INTEGER = new Integer(Integer.MIN_VALUE);
- final Long MAX_LONG = new Long(Long.MAX_VALUE);
- final Long MIN_LONG = new Long(Long.MIN_VALUE);
- final Double MAX_DOUBLE = new Double(Double.MAX_VALUE);
- final Double MIN_DOUBLE = new Double(Double.MIN_VALUE);
+ SummaryInformation si = getSummaryInformation(poifs);
+ DocumentSummaryInformation dsi = getDocumentSummaryInformation(poifs);
si.setApplicationName(P_APPLICATION_NAME);
si.setAuthor(P_AUTHOR);
@@ -322,76 +321,71 @@ public class TestWriteWellKnown extends
dsi.setScale(P_SCALE);
dsi.setSlideCount(P_SLIDE_COUNT);
- CustomProperties customProperties = dsi.getCustomProperties();
- if (customProperties == null)
- customProperties = new CustomProperties();
- customProperties.put("Schl\u00fcssel \u00e4", "Wert \u00e4");
- customProperties.put("Schl\u00fcssel \u00e4\u00f6", "Wert \u00e4\u00f6");
- customProperties.put("Schl\u00fcssel \u00e4\u00f6\u00fc", "Wert \u00e4\u00f6\u00fc");
- customProperties.put("Schl\u00fcssel \u00e4\u00f6\u00fc\u00d6", "Wert \u00e4\u00f6\u00fc\u00d6");
- customProperties.put("positive_Integer", POSITIVE_INTEGER);
- customProperties.put("positive_Long", POSITIVE_LONG);
- customProperties.put("positive_Double", POSITIVE_DOUBLE);
- customProperties.put("negative_Integer", NEGATIVE_INTEGER);
- customProperties.put("negative_Long", NEGATIVE_LONG);
- customProperties.put("negative_Double", NEGATIVE_DOUBLE);
- customProperties.put("Boolean", Boolean.TRUE);
- customProperties.put("Date", now);
- customProperties.put("max_Integer", MAX_INTEGER);
- customProperties.put("min_Integer", MIN_INTEGER);
- customProperties.put("max_Long", MAX_LONG);
- customProperties.put("min_Long", MIN_LONG);
- customProperties.put("max_Double", MAX_DOUBLE);
- customProperties.put("min_Double", MIN_DOUBLE);
+ CustomProperties cps = dsi.getCustomProperties();
+ assertNull(cps);
+ cps = new CustomProperties();
+ cps.put("Schl\u00fcssel \u00e4", "Wert \u00e4");
+ cps.put("Schl\u00fcssel \u00e4\u00f6", "Wert \u00e4\u00f6");
+ cps.put("Schl\u00fcssel \u00e4\u00f6\u00fc", "Wert \u00e4\u00f6\u00fc");
+ cps.put("Schl\u00fcssel \u00e4\u00f6\u00fc\u00d6", "Wert \u00e4\u00f6\u00fc\u00d6");
+ cps.put("positive_Integer", POSITIVE_INTEGER);
+ cps.put("positive_Long", POSITIVE_LONG);
+ cps.put("positive_Double", POSITIVE_DOUBLE);
+ cps.put("negative_Integer", NEGATIVE_INTEGER);
+ cps.put("negative_Long", NEGATIVE_LONG);
+ cps.put("negative_Double", NEGATIVE_DOUBLE);
+ cps.put("Boolean", Boolean.TRUE);
+ cps.put("Date", now);
+ cps.put("max_Integer", MAX_INTEGER);
+ cps.put("min_Integer", MIN_INTEGER);
+ cps.put("max_Long", MAX_LONG);
+ cps.put("min_Long", MIN_LONG);
+ cps.put("max_Double", MAX_DOUBLE);
+ cps.put("min_Double", MIN_DOUBLE);
// Check the keys went in
- assertTrue(customProperties.containsKey("Schl\u00fcssel \u00e4"));
- assertTrue(customProperties.containsKey("Boolean"));
+ assertTrue(cps.containsKey("Schl\u00fcssel \u00e4"));
+ assertTrue(cps.containsKey("Boolean"));
// Check the values went in
- assertEquals("Wert \u00e4", customProperties.get("Schl\u00fcssel \u00e4"));
- assertEquals(Boolean.TRUE, customProperties.get("Boolean"));
- assertTrue(customProperties.containsValue(Boolean.TRUE));
- assertTrue(customProperties.containsValue("Wert \u00e4"));
+ assertEquals("Wert \u00e4", cps.get("Schl\u00fcssel \u00e4"));
+ assertEquals(Boolean.TRUE, cps.get("Boolean"));
+ assertTrue(cps.containsValue(Boolean.TRUE));
+ assertTrue(cps.containsValue("Wert \u00e4"));
// Check that things that aren't in aren't in
- assertFalse(customProperties.containsKey("False Boolean"));
- assertFalse(customProperties.containsValue(Boolean.FALSE));
+ assertFalse(cps.containsKey("False Boolean"));
+ assertFalse(cps.containsValue(Boolean.FALSE));
// Save as our custom properties
- dsi.setCustomProperties(customProperties);
+ dsi.setCustomProperties(cps);
/* Write the summary information stream and the document summary
* information stream to the POI filesystem. */
- si.write(dir, siEntry.getName());
- dsi.write(dir, dsiEntry.getName());
+ si.write(poifs.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
+ dsi.write(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
/* Write the POI filesystem to a (temporary) file <em>doc2</em>
* and close the latter. */
- final File doc2 = TempFile.createTempFile("POI_HPSF_Test.", ".tmp");
- doc2.deleteOnExit();
- OutputStream out = new FileOutputStream(doc2);
+ OutputStream out = new FileOutputStream(fileOut);
poifs.writeFilesystem(out);
out.close();
-
- /*
- * Open <em>doc2</em> for reading and check summary information and
- * document summary information. All properties written before must be
- * found in the property streams of <em>doc2</em> and have the correct
- * values.
- */
- poifs = new POIFSFileSystem(new FileInputStream(doc2));
- dir = poifs.getRoot();
- siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
- dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
-
- dis = new DocumentInputStream(siEntry);
- ps = new PropertySet(dis);
- si = new SummaryInformation(ps);
- dis = new DocumentInputStream(dsiEntry);
- ps = new PropertySet(dis);
- dsi = new DocumentSummaryInformation(ps);
+ poifs.close();
+
+ return cps;
+ }
+
+ /*
+ * Open <em>doc2</em> for reading and check summary information and
+ * document summary information. All properties written before must be
+ * found in the property streams of <em>doc2</em> and have the correct
+ * values.
+ */
+ private static CustomProperties write2ndFile(File fileIn, File fileOut) throws Exception {
+ NPOIFSFileSystem poifs = new NPOIFSFileSystem(fileIn, false);
+ SummaryInformation si = getSummaryInformation(poifs);
+ DocumentSummaryInformation dsi = getDocumentSummaryInformation(poifs);
assertEquals(P_APPLICATION_NAME, si.getApplicationName());
assertEquals(P_AUTHOR, si.getAuthor());
@@ -429,7 +423,7 @@ public class TestWriteWellKnown extends
assertEquals(P_SLIDE_COUNT, dsi.getSlideCount());
final CustomProperties cps = dsi.getCustomProperties();
- assertEquals(customProperties, cps);
+ assertNotNull(cps);
assertNull(cps.get("No value available"));
assertEquals("Wert \u00e4", cps.get("Schl\u00fcssel \u00e4"));
assertEquals("Wert \u00e4\u00f6", cps.get("Schl\u00fcssel \u00e4\u00f6"));
@@ -492,93 +486,108 @@ public class TestWriteWellKnown extends
/*
* <li><p>Write the summary information stream and the document summary
* information stream to the POI filesystem. */
- si.write(dir, siEntry.getName());
- dsi.write(dir, dsiEntry.getName());
+ si.write(poifs.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
+ dsi.write(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
/*
* <li><p>Write the POI filesystem to a (temporary) file <em>doc3</em>
* and close the latter. */
- final File doc3 = TempFile.createTempFile("POI_HPSF_Test.", ".tmp");
- doc3.deleteOnExit();
- out = new FileOutputStream(doc3);
+ FileOutputStream out = new FileOutputStream(fileOut);
poifs.writeFilesystem(out);
out.close();
+ poifs.close();
+
+ return cps;
+ }
+
+ /*
+ * Open <em>doc3</em> for reading and check summary information
+ * and document summary information. All properties removed before must not
+ * be found in the property streams of <em>doc3</em>.
+ */
+ private static CustomProperties write3rdFile(File fileIn, File fileOut) throws Exception {
+ NPOIFSFileSystem poifs = new NPOIFSFileSystem(fileIn, false);
+ SummaryInformation si = getSummaryInformation(poifs);
+ DocumentSummaryInformation dsi = getDocumentSummaryInformation(poifs);
- /*
- * Open <em>doc3</em> for reading and check summary information
- * and document summary information. All properties removed before must not
- * be found in the property streams of <em>doc3</em>.
- */
- poifs = new POIFSFileSystem(new FileInputStream(doc3));
- dir = poifs.getRoot();
- siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
- dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
-
- dis = new DocumentInputStream(siEntry);
- ps = new PropertySet(dis);
- si = new SummaryInformation(ps);
- dis = new DocumentInputStream(dsiEntry);
- ps = new PropertySet(dis);
- dsi = new DocumentSummaryInformation(ps);
-
- assertEquals(null, si.getApplicationName());
- assertEquals(null, si.getAuthor());
+ assertNull(si.getApplicationName());
+ assertNull(si.getAuthor());
assertEquals(0, si.getCharCount());
assertTrue(si.wasNull());
- assertEquals(null, si.getComments());
- assertEquals(null, si.getCreateDateTime());
+ assertNull(si.getComments());
+ assertNull(si.getCreateDateTime());
assertEquals(0, si.getEditTime());
assertTrue(si.wasNull());
- assertEquals(null, si.getKeywords());
- assertEquals(null, si.getLastAuthor());
- assertEquals(null, si.getLastPrinted());
- assertEquals(null, si.getLastSaveDateTime());
+ assertNull(si.getKeywords());
+ assertNull(si.getLastAuthor());
+ assertNull(si.getLastPrinted());
+ assertNull(si.getLastSaveDateTime());
assertEquals(0, si.getPageCount());
assertTrue(si.wasNull());
- assertEquals(null, si.getRevNumber());
+ assertNull(si.getRevNumber());
assertEquals(0, si.getSecurity());
assertTrue(si.wasNull());
- assertEquals(null, si.getSubject());
- assertEquals(null, si.getTemplate());
- assertEquals(null, si.getThumbnail());
- assertEquals(null, si.getTitle());
+ assertNull(si.getSubject());
+ assertNull(si.getTemplate());
+ assertNull(si.getThumbnail());
+ assertNull(si.getTitle());
assertEquals(0, si.getWordCount());
assertTrue(si.wasNull());
assertEquals(0, dsi.getByteCount());
assertTrue(dsi.wasNull());
- assertEquals(null, dsi.getCategory());
- assertEquals(null, dsi.getCustomProperties());
- // FIXME (byte array properties not yet implemented): assertEquals(null, dsi.getDocparts());
- // FIXME (byte array properties not yet implemented): assertEquals(null, dsi.getHeadingPair());
+ assertNull(dsi.getCategory());
+ assertNull(dsi.getCustomProperties());
+ // FIXME (byte array properties not yet implemented): assertNull(dsi.getDocparts());
+ // FIXME (byte array properties not yet implemented): assertNull(dsi.getHeadingPair());
assertEquals(0, dsi.getHiddenCount());
assertTrue(dsi.wasNull());
assertEquals(0, dsi.getLineCount());
assertTrue(dsi.wasNull());
- assertEquals(false, dsi.getLinksDirty());
+ assertFalse(dsi.getLinksDirty());
assertTrue(dsi.wasNull());
- assertEquals(null, dsi.getManager());
+ assertNull(dsi.getManager());
assertEquals(0, dsi.getMMClipCount());
assertTrue(dsi.wasNull());
assertEquals(0, dsi.getNoteCount());
assertTrue(dsi.wasNull());
assertEquals(0, dsi.getParCount());
assertTrue(dsi.wasNull());
- assertEquals(null, dsi.getPresentationFormat());
- assertEquals(false, dsi.getScale());
+ assertNull(dsi.getPresentationFormat());
+ assertFalse(dsi.getScale());
assertTrue(dsi.wasNull());
assertEquals(0, dsi.getSlideCount());
assertTrue(dsi.wasNull());
+ poifs.close();
+
+ return dsi.getCustomProperties();
}
+ private static SummaryInformation getSummaryInformation(NPOIFSFileSystem poifs) throws Exception {
+ DocumentInputStream dis = poifs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME);
+ PropertySet ps = new PropertySet(dis);
+ SummaryInformation si = new SummaryInformation(ps);
+ dis.close();
+ return si;
+ }
+
+ private static DocumentSummaryInformation getDocumentSummaryInformation(NPOIFSFileSystem poifs) throws Exception {
+ DocumentInputStream dis = poifs.createDocumentInputStream(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
+ PropertySet ps = new PropertySet(dis);
+ DocumentSummaryInformation dsi = new DocumentSummaryInformation(ps);
+ dis.close();
+ return dsi;
+ }
-
+
+
/**
* <p>Tests the simplified custom properties by reading them from the
* available test files.</p>
*
* @throws Throwable if anything goes wrong.
*/
+ @Test
public void testReadCustomPropertiesFromFiles() throws Throwable
{
final AllDataFilesTester.TestTask task = new AllDataFilesTester.TestTask()
@@ -590,43 +599,35 @@ public class TestWriteWellKnown extends
UnexpectedPropertySetTypeException
{
/* Read a test document <em>doc</em> into a POI filesystem. */
- final POIFSFileSystem poifs = new POIFSFileSystem(new FileInputStream(file));
- final DirectoryEntry dir = poifs.getRoot();
- DocumentEntry dsiEntry = null;
- try
- {
- dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
- }
- catch (FileNotFoundException ex)
- {
+ NPOIFSFileSystem poifs = null;
+ try {
+ poifs = new NPOIFSFileSystem(file);
+ final DirectoryEntry dir = poifs.getRoot();
/*
- * A missing document summary information stream is not an error
- * and therefore silently ignored here.
+ * If there is a document summry information stream, read it from
+ * the POI filesystem, else create a new one.
*/
- }
-
- /*
- * If there is a document summry information stream, read it from
- * the POI filesystem, else create a new one.
- */
- DocumentSummaryInformation dsi;
- if (dsiEntry != null)
- {
- final DocumentInputStream dis = new DocumentInputStream(dsiEntry);
- final PropertySet ps = new PropertySet(dis);
- dsi = new DocumentSummaryInformation(ps);
- }
- else
- dsi = PropertySetFactory.newDocumentSummaryInformation();
- final CustomProperties cps = dsi.getCustomProperties();
-
- if (cps == null)
- /* The document does not have custom properties. */
- return;
-
- for (CustomProperty cp : cps.values()) {
- cp.getName();
- cp.getValue();
+ DocumentSummaryInformation dsi;
+ if (dir.hasEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)) {
+ final DocumentInputStream dis = poifs.createDocumentInputStream(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
+ final PropertySet ps = new PropertySet(dis);
+ dsi = new DocumentSummaryInformation(ps);
+ dis.close();
+ } else {
+ dsi = PropertySetFactory.newDocumentSummaryInformation();
+ }
+ final CustomProperties cps = dsi.getCustomProperties();
+
+ if (cps == null)
+ /* The document does not have custom properties. */
+ return;
+
+ for (CustomProperty cp : cps.values()) {
+ cp.getName();
+ cp.getValue();
+ }
+ } finally {
+ if (poifs != null) poifs.close();
}
}
};
@@ -657,6 +658,7 @@ public class TestWriteWellKnown extends
/**
* <p>Tests basic custom property features.</p>
*/
+ @Test
public void testCustomerProperties()
{
final String KEY = "Schl\u00fcssel \u00e4";
@@ -695,6 +697,7 @@ public class TestWriteWellKnown extends
* <p>Tests reading custom properties from a section including reading
* custom properties which are not pure.</p>
*/
+ @Test
public void testGetCustomerProperties()
{
final int ID_1 = 2;
@@ -709,7 +712,7 @@ public class TestWriteWellKnown extends
/* A document summary information set stream by default does have custom properties. */
cps = dsi.getCustomProperties();
- assertEquals(null, cps);
+ assertNull(cps);
/* Test an empty custom properties set. */
s = new MutableSection();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org