Author: centic
Date: Wed Dec 26 13:28:32 2018
New Revision: 1849765
URL: http://svn.apache.org/viewvc?rev=1849765&view=rev
Log:
Add some simple coverage of HSLF-Dev-Tools
Added:
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/BasePPTIteratingTest.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestPPDrawingTextListing.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestPPTXMLDump.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSLWTListing.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSLWTTextListing.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideAndNotesAtomListing.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideIdListing.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideShowDumper.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideShowRecordDumper.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestTextStyleListing.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestUserEditAndPersistListing.java
Modified:
poi/trunk/src/java/org/apache/poi/util/IOUtils.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPDrawingTextListing.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideAndNotesAtomListing.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideIdListing.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowRecordDumper.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java
poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherDump.java
poi/trunk/src/testcases/org/apache/poi/hssf/dev/BaseXLSIteratingTest.java
poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java
poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java
poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java
poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestReSave.java
poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java
Modified: poi/trunk/src/java/org/apache/poi/util/IOUtils.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/IOUtils.java?rev=1849765&r1=1849764&r2=1849765&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/IOUtils.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/IOUtils.java Wed Dec 26 13:28:32 2018
@@ -562,7 +562,7 @@ public final class IOUtils {
public static byte[] safelyAllocate(long length, int maxLength) {
if (length < 0L) {
- throw new RecordFormatException("Can't allocate an array of length
< 0");
+ throw new RecordFormatException("Can't allocate an array of length
< 0, but had " + length + " and " + maxLength);
}
if (length > (long)Integer.MAX_VALUE) {
throw new RecordFormatException("Can't allocate an array >
"+Integer.MAX_VALUE);
Modified:
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPDrawingTextListing.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPDrawingTextListing.java?rev=1849765&r1=1849764&r2=1849765&view=diff
==============================================================================
---
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPDrawingTextListing.java
(original)
+++
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPDrawingTextListing.java
Wed Dec 26 13:28:32 2018
@@ -39,43 +39,44 @@ public final class PPDrawingTextListing
System.exit(1);
}
- HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
+ try (HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0])) {
- // Find PPDrawings at any second level position
- Record[] records = ss.getRecords();
- for(int i=0; i<records.length; i++) {
- Record[] children = records[i].getChildRecords();
- if(children != null && children.length != 0) {
- for(int j=0; j<children.length; j++) {
- if(children[j] instanceof PPDrawing) {
- System.out.println("Found
PPDrawing at " + j + " in top level record " + i + " (" +
records[i].getRecordType() + ")" );
-
- // Look for
EscherTextboxWrapper's
- PPDrawing ppd =
(PPDrawing)children[j];
- EscherTextboxWrapper[] wrappers
= ppd.getTextboxWrappers();
- System.out.println(" Has " +
wrappers.length + " textbox wrappers within");
-
- // Loop over the wrappers,
showing what they contain
- for(int k=0; k<wrappers.length;
k++) {
- EscherTextboxWrapper
tbw = wrappers[k];
- System.out.println("
" + k + " has " + tbw.getChildRecords().length + " PPT atoms within");
-
- // Loop over the
records, printing the text
- Record[] pptatoms =
tbw.getChildRecords();
- for(int l=0;
l<pptatoms.length; l++) {
- String text =
null;
- if(pptatoms[l]
instanceof TextBytesAtom) {
-
TextBytesAtom tba = (TextBytesAtom)pptatoms[l];
- text =
tba.getText();
- }
- if(pptatoms[l]
instanceof TextCharsAtom) {
-
TextCharsAtom tca = (TextCharsAtom)pptatoms[l];
- text =
tca.getText();
- }
-
- if(text !=
null) {
- text =
text.replace('\r','\n');
-
System.out.println(" ''" + text + "''");
+ // Find PPDrawings at any second level position
+ Record[] records = ss.getRecords();
+ for (int i = 0; i < records.length; i++) {
+ Record[] children =
records[i].getChildRecords();
+ if (children != null && children.length != 0) {
+ for (int j = 0; j < children.length;
j++) {
+ if (children[j] instanceof
PPDrawing) {
+
System.out.println("Found PPDrawing at " + j + " in top level record " + i + "
(" + records[i].getRecordType() + ")");
+
+ // Look for
EscherTextboxWrapper's
+ PPDrawing ppd =
(PPDrawing) children[j];
+ EscherTextboxWrapper[]
wrappers = ppd.getTextboxWrappers();
+ System.out.println("
Has " + wrappers.length + " textbox wrappers within");
+
+ // Loop over the
wrappers, showing what they contain
+ for (int k = 0; k <
wrappers.length; k++) {
+
EscherTextboxWrapper tbw = wrappers[k];
+
System.out.println(" " + k + " has " + tbw.getChildRecords().length + " PPT
atoms within");
+
+ // Loop over
the records, printing the text
+ Record[]
pptatoms = tbw.getChildRecords();
+ for (Record
pptatom : pptatoms) {
+ String
text = null;
+ if
(pptatom instanceof TextBytesAtom) {
+
TextBytesAtom tba = (TextBytesAtom) pptatom;
+
text = tba.getText();
+ }
+ if
(pptatom instanceof TextCharsAtom) {
+
TextCharsAtom tca = (TextCharsAtom) pptatom;
+
text = tca.getText();
+ }
+
+ if
(text != null) {
+
text = text.replace('\r', '\n');
+
System.out.println(" ''" + text + "''");
+ }
}
}
}
@@ -83,7 +84,5 @@ public final class PPDrawingTextListing
}
}
}
-
- ss.close();
}
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java?rev=1849765&r1=1849764&r2=1849765&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java Wed
Dec 26 13:28:32 2018
@@ -54,12 +54,9 @@ public final class PPTXMLDump {
private boolean hexHeader = true;
public PPTXMLDump(File ppt) throws IOException {
- POIFSFileSystem fs = new POIFSFileSystem(ppt, true);
- try {
+ try (POIFSFileSystem fs = new POIFSFileSystem(ppt, true)) {
docstream = readEntry(fs, HSLFSlideShow.POWERPOINT_DOCUMENT);
pictstream = readEntry(fs, PICTURES_ENTRY);
- } finally {
- fs.close();
}
}
@@ -69,20 +66,17 @@ public final class PPTXMLDump {
if (!dn.hasEntry(entry)) {
return null;
}
- InputStream is = dn.createDocumentInputStream(entry);
- try {
+ try (InputStream is = dn.createDocumentInputStream(entry)) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
IOUtils.copy(is, bos);
return bos.toByteArray();
- } finally {
- is.close();
}
}
/**
* Dump the structure of the supplied PPT file into XML
* @param outWriter <code>Writer</code> to write out
- * @throws java.io.IOException
+ * @throws java.io.IOException If writing to the writer fails
*/
public void dump(Writer outWriter) throws IOException {
this.out = outWriter;
@@ -98,7 +92,9 @@ public final class PPTXMLDump {
//dump the structure of the powerpoint document
write(out, "<PowerPointDocument>" + CR, padding);
padding++;
- dump(docstream, 0, docstream.length, padding);
+ if(docstream != null) {
+ dump(docstream, 0, docstream.length, padding);
+ }
padding--;
write(out, "</PowerPointDocument>" + CR, padding);
padding--;
@@ -111,7 +107,7 @@ public final class PPTXMLDump {
* @param offset offset from the beginning of the document
* @param length of the document
* @param padding used for formatting results
- * @throws java.io.IOException
+ * @throws java.io.IOException If writing out information fails
*/
public void dump(byte[] data, int offset, int length, int padding) throws
IOException {
int pos = offset;
@@ -158,16 +154,24 @@ public final class PPTXMLDump {
* Dumps the Pictures OLE stream into XML.
*
* @param data from the Pictures OLE data stream
- * @param padding
- * @throws java.io.IOException
+ * @param padding How many leading blanks to add in the output
+ * @throws java.io.IOException If writing out information fails
*/
public void dumpPictures(byte[] data, int padding) throws IOException {
int pos = 0;
while (pos < data.length) {
byte[] header = new byte[PICT_HEADER_SIZE];
+ if(data.length - pos < header.length) {
+ // corrupt file, cannot read header
+ return;
+ }
System.arraycopy(data, pos, header, 0, header.length);
int size = LittleEndian.getInt(header, 4) - 17;
+ if(size < 0) {
+ // corrupt file, negative image size
+ return;
+ }
byte[] pictdata = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
System.arraycopy(data, pos + PICT_HEADER_SIZE, pictdata, 0,
pictdata.length);
pos += PICT_HEADER_SIZE + size;
@@ -184,7 +188,6 @@ public final class PPTXMLDump {
padding--;
write(out, "</picture>" + CR, padding);
padding--;
-
}
}
@@ -272,5 +275,4 @@ public final class PPTXMLDump {
(byte) '4', (byte) '5', (byte) '6', (byte) '7',
(byte) '8', (byte) '9', (byte) 'A', (byte) 'B',
(byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F'};
-
}
Modified:
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideAndNotesAtomListing.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideAndNotesAtomListing.java?rev=1849765&r1=1849764&r2=1849765&view=diff
==============================================================================
---
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideAndNotesAtomListing.java
(original)
+++
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideAndNotesAtomListing.java
Wed Dec 26 13:28:32 2018
@@ -41,7 +41,7 @@ public final class SlideAndNotesAtomList
}
HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
- System.out.println("");
+ System.out.println();
// Find either Slides or Notes
Record[] records = ss.getRecords();
@@ -55,14 +55,14 @@ public final class SlideAndNotesAtomList
System.out.println("Found Slide at " + i);
System.out.println(" Slide's master ID is " +
sa.getMasterID());
System.out.println(" Slide's notes ID is " +
sa.getNotesID());
- System.out.println("");
+ System.out.println();
}
if(r instanceof Notes) {
Notes n = (Notes)r;
NotesAtom na = n.getNotesAtom();
System.out.println("Found Notes at " + i);
System.out.println(" Notes ID is " +
na.getSlideID());
- System.out.println("");
+ System.out.println();
}
}
Modified:
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideIdListing.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideIdListing.java?rev=1849765&r1=1849764&r2=1849765&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideIdListing.java
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideIdListing.java
Wed Dec 26 13:28:32 2018
@@ -61,23 +61,23 @@ public final class SlideIdListing {
// Grab any records that interest us
Document document = null;
- for(int i=0; i<latestRecords.length; i++) {
- if(latestRecords[i] instanceof Document) {
- document = (Document)latestRecords[i];
+ for (Record latestRecord : latestRecords) {
+ if (latestRecord instanceof Document) {
+ document = (Document) latestRecord;
}
}
- System.out.println("");
+ System.out.println();
// Look for SlidePersistAtoms, and report what they have to
// say about possible slide IDs
SlideListWithText[] slwts = document.getSlideListWithTexts();
- for(int i=0; i<slwts.length; i++) {
- Record[] cr = slwts[i].getChildRecords();
- for(int j=0; j<cr.length; j++) {
- if(cr[j] instanceof SlidePersistAtom) {
- SlidePersistAtom spa =
(SlidePersistAtom)cr[j];
+ for (SlideListWithText slwt : slwts) {
+ Record[] cr = slwt.getChildRecords();
+ for (Record record : cr) {
+ if (record instanceof SlidePersistAtom) {
+ SlidePersistAtom spa =
(SlidePersistAtom) record;
System.out.println("SlidePersistAtom
knows about slide:");
System.out.println("\t" +
spa.getRefID());
System.out.println("\t" +
spa.getSlideIdentifier());
@@ -85,7 +85,7 @@ public final class SlideIdListing {
}
}
- System.out.println("");
+ System.out.println();
// Look for latest core records that are slides or notes
for(int i=0; i<latestRecords.length; i++) {
@@ -100,7 +100,7 @@ public final class SlideIdListing {
System.out.println("\tNotes ID is " +
sa.getNotesID());
}
}
- System.out.println("");
+ System.out.println();
for(int i=0; i<latestRecords.length; i++) {
if(latestRecords[i] instanceof Notes) {
Notes n = (Notes)latestRecords[i];
@@ -113,27 +113,24 @@ public final class SlideIdListing {
}
}
- System.out.println("");
+ System.out.println();
// Find any persist ones first
int pos = 0;
- for(int i=0; i<records.length; i++) {
- Record r = records[i];
-
- if(r.getRecordType() == 6001l) {
+ for (Record r : records) {
+ if (r.getRecordType() == 6001L) {
// PersistPtrFullBlock
System.out.println("Found PersistPtrFullBlock
at " + pos + " (" + Integer.toHexString(pos) + ")");
}
- if(r.getRecordType() == 6002l) {
+ if (r.getRecordType() == 6002L) {
// PersistPtrIncrementalBlock
System.out.println("Found
PersistPtrIncrementalBlock at " + pos + " (" + Integer.toHexString(pos) + ")");
- PersistPtrHolder pph = (PersistPtrHolder)r;
+ PersistPtrHolder pph = (PersistPtrHolder) r;
// Check the sheet offsets
int[] sheetIDs = pph.getKnownSlideIDs();
- Map<Integer,Integer> sheetOffsets =
pph.getSlideLocationsLookup();
- for(int j=0; j<sheetIDs.length; j++) {
- Integer id = sheetIDs[j];
+ Map<Integer, Integer> sheetOffsets =
pph.getSlideLocationsLookup();
+ for (Integer id : sheetIDs) {
Integer offset = sheetOffsets.get(id);
System.out.println(" Knows about sheet
" + id);
@@ -143,7 +140,7 @@ public final class SlideIdListing {
System.out.println(" The record at
that pos is of type " + atPos.getRecordType());
System.out.println(" The record at
that pos has class " + atPos.getClass().getName());
- if(! (atPos instanceof
PositionDependentRecord)) {
+ if (!(atPos instanceof
PositionDependentRecord)) {
System.out.println(" ** The
record class isn't position aware! **");
}
}
@@ -157,7 +154,7 @@ public final class SlideIdListing {
ss.close();
- System.out.println("");
+ System.out.println();
}
Modified:
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowRecordDumper.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowRecordDumper.java?rev=1849765&r1=1849764&r2=1849765&view=diff
==============================================================================
---
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowRecordDumper.java
(original)
+++
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowRecordDumper.java
Wed Dec 26 13:28:32 2018
@@ -56,7 +56,6 @@ public final class SlideShowRecordDumper
* dump of what it contains
*/
public static void main(String[] args) throws IOException {
- String filename = "";
boolean verbose = false;
boolean escher = false;
@@ -81,12 +80,14 @@ public final class SlideShowRecordDumper
return;
}
- filename = args[ndx];
+ String filename = args[ndx];
SlideShowRecordDumper foo = new SlideShowRecordDumper(System.out,
filename, verbose, escher);
foo.printDump();
+
+ foo.doc.close();
}
public static void printUsage() {
@@ -118,11 +119,11 @@ public final class SlideShowRecordDumper
}
public String makeHex(int number, int padding) {
- String hex = Integer.toHexString(number).toUpperCase(Locale.ROOT);
+ StringBuilder hex = new
StringBuilder(Integer.toHexString(number).toUpperCase(Locale.ROOT));
while (hex.length() < padding) {
- hex = "0" + hex;
+ hex.insert(0, "0");
}
- return hex;
+ return hex.toString();
}
public String reverseHex(String s) {
@@ -186,7 +187,7 @@ public final class SlideShowRecordDumper
for (Record child : etw.getChildRecords()) {
if (child instanceof StyleTextPropAtom) {
// need preceding Text[Chars|Bytes]Atom to initialize the data
structure
- String text = null;
+ String text;
if (prevChild instanceof TextCharsAtom) {
text = ((TextCharsAtom)prevChild).getText();
} else if (prevChild instanceof TextBytesAtom) {
@@ -227,8 +228,7 @@ public final class SlideShowRecordDumper
public void walkTree(int depth, int pos, Record[] records, int indent)
throws IOException {
String ind = tabs.substring(0, indent);
- for (int i = 0; i < records.length; i++) {
- Record r = records[i];
+ for (Record r : records) {
if (r == null) {
ps.println(ind + "At position " + pos + " (" + makeHex(pos, 6)
+ "):");
ps.println(ind + "Warning! Null record found.");
@@ -242,49 +242,49 @@ public final class SlideShowRecordDumper
String hexType = makeHex((int) r.getRecordType(), 4);
String rHexType = reverseHex(hexType);
- // Grab the hslf.record type
- Class<? extends Record> c = r.getClass();
- String cname = c.toString();
- if(cname.startsWith("class ")) {
- cname = cname.substring(6);
- }
- if(cname.startsWith("org.apache.poi.hslf.record.")) {
- cname = cname.substring(27);
- }
+ // Grab the hslf.record type
+ Class<? extends Record> c = r.getClass();
+ String cname = c.toString();
+ if (cname.startsWith("class ")) {
+ cname = cname.substring(6);
+ }
+ if (cname.startsWith("org.apache.poi.hslf.record.")) {
+ cname = cname.substring(27);
+ }
- // Display the record
- ps.println(ind + "At position " + pos + " (" + makeHex(pos,6) +
"):");
- ps.println(ind + " Record is of type " + cname);
- ps.println(ind + " Type is " + r.getRecordType() + " (" +
hexType + " -> " + rHexType + " )");
- ps.println(ind + " Len is " + (len-8) + " (" +
makeHex((len-8),8) + "), on disk len is " + len );
-
- // print additional information for drawings and atoms
- if (optEscher && cname.equals("PPDrawing")) {
- DefaultEscherRecordFactory factory = new
HSLFEscherRecordFactory();
-
- ByteArrayOutputStream baos = new
ByteArrayOutputStream();
- r.writeOut(baos);
- byte[] b = baos.toByteArray();
-
- EscherRecord er = factory.createRecord(b, 0);
- er.fillFields(b, 0, factory);
-
- printEscherRecord( er, indent+1 );
-
- } else if(optVerbose && r.getChildRecords() == null) {
- String recData = getPrintableRecordContents(r);
- ps.println(ind + recData );
- }
+ // Display the record
+ ps.println(ind + "At position " + pos + " (" + makeHex(pos, 6) +
"):");
+ ps.println(ind + " Record is of type " + cname);
+ ps.println(ind + " Type is " + r.getRecordType() + " (" + hexType
+ " -> " + rHexType + " )");
+ ps.println(ind + " Len is " + (len - 8) + " (" + makeHex((len -
8), 8) + "), on disk len is " + len);
+
+ // print additional information for drawings and atoms
+ if (optEscher && cname.equals("PPDrawing")) {
+ DefaultEscherRecordFactory factory = new
HSLFEscherRecordFactory();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ r.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ EscherRecord er = factory.createRecord(b, 0);
+ er.fillFields(b, 0, factory);
+
+ printEscherRecord(er, indent + 1);
+
+ } else if (optVerbose && r.getChildRecords() == null) {
+ String recData = getPrintableRecordContents(r);
+ ps.println(ind + recData);
+ }
- ps.println();
+ ps.println();
- // If it has children, show them
- if(r.getChildRecords() != null) {
- walkTree((depth+3),pos+8,r.getChildRecords(), indent+1);
- }
+ // If it has children, show them
+ if (r.getChildRecords() != null) {
+ walkTree((depth + 3), pos + 8, r.getChildRecords(), indent +
1);
+ }
- // Wind on the position marker
- pos += len;
- }
+ // Wind on the position marker
+ pos += len;
+ }
}
}
Modified:
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java?rev=1849765&r1=1849764&r2=1849765&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java
Wed Dec 26 13:28:32 2018
@@ -45,25 +45,24 @@ public final class TextStyleListing {
// Find the documents, and then their SLWT
Record[] records = ss.getRecords();
- for(int i=0; i<records.length; i++) {
- if(records[i].getRecordType() == 1000l) {
- Record docRecord = records[i];
- Record[] docChildren =
docRecord.getChildRecords();
- for(int j=0; j<docChildren.length; j++) {
- if(docChildren[j] instanceof
SlideListWithText) {
- Record[] slwtChildren =
docChildren[j].getChildRecords();
+ for (Record record : records) {
+ if (record.getRecordType() == 1000L) {
+ Record[] docChildren = record.getChildRecords();
+ for (Record docChild : docChildren) {
+ if (docChild instanceof
SlideListWithText) {
+ Record[] slwtChildren =
docChild.getChildRecords();
int lastTextLen = -1;
- for(int k=0;
k<slwtChildren.length; k++) {
- if(slwtChildren[k]
instanceof TextCharsAtom) {
- lastTextLen =
((TextCharsAtom)slwtChildren[k]).getText().length();
+ for (Record slwtChild :
slwtChildren) {
+ if (slwtChild
instanceof TextCharsAtom) {
+ lastTextLen =
((TextCharsAtom) slwtChild).getText().length();
}
- if(slwtChildren[k]
instanceof TextBytesAtom) {
- lastTextLen =
((TextBytesAtom)slwtChildren[k]).getText().length();
+ if (slwtChild
instanceof TextBytesAtom) {
+ lastTextLen =
((TextBytesAtom) slwtChild).getText().length();
}
- if(slwtChildren[k]
instanceof StyleTextPropAtom) {
-
StyleTextPropAtom stpa = (StyleTextPropAtom)slwtChildren[k];
+ if (slwtChild
instanceof StyleTextPropAtom) {
+
StyleTextPropAtom stpa = (StyleTextPropAtom) slwtChild;
stpa.setParentTextSize(lastTextLen);
showStyleTextPropAtom(stpa);
}
Modified:
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java?rev=1849765&r1=1849764&r2=1849765&view=diff
==============================================================================
---
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java
(original)
+++
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java
Wed Dec 26 13:28:32 2018
@@ -47,7 +47,7 @@ public final class UserEditAndPersistLis
// Create the slideshow object, for normal working with
HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
fileContents = ss.getUnderlyingBytes();
- System.out.println("");
+ System.out.println();
// Find any persist ones first
int pos = 0;
@@ -85,7 +85,7 @@ public final class UserEditAndPersistLis
pos += baos.size();
}
- System.out.println("");
+ System.out.println();
pos = 0;
// Now look for UserEditAtoms
@@ -105,7 +105,7 @@ public final class UserEditAndPersistLis
pos += baos.size();
}
- System.out.println("");
+ System.out.println();
// Query the CurrentUserAtom
@@ -113,7 +113,7 @@ public final class UserEditAndPersistLis
System.out.println("Checking Current User Atom");
System.out.println(" Thinks the CurrentEditOffset is " +
cua.getCurrentEditOffset());
- System.out.println("");
+ System.out.println();
ss.close();
}
Added:
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/BasePPTIteratingTest.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/BasePPTIteratingTest.java?rev=1849765&view=auto
==============================================================================
---
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/BasePPTIteratingTest.java
(added)
+++
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/BasePPTIteratingTest.java
Wed Dec 26 13:28:32 2018
@@ -0,0 +1,139 @@
+/* ====================================================================
+ 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.hslf.dev;
+
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
+import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;
+import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.LocaleUtil;
+import org.apache.poi.util.NullOutputStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.io.File;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(Parameterized.class)
+public abstract class BasePPTIteratingTest {
+ protected static final OutputStream NULL_OUTPUT_STREAM = new
NullOutputStream();
+
+ protected static final Set<String> OLD_FILES = new HashSet<>();
+ static {
+ OLD_FILES.add("PPT95.ppt");
+ OLD_FILES.add("pp40only.ppt");
+ }
+
+ protected static final Set<String> ENCRYPTED_FILES = new HashSet<>();
+ static {
+ ENCRYPTED_FILES.add("cryptoapi-proc2356.ppt");
+ ENCRYPTED_FILES.add("Password_Protected-np-hello.ppt");
+ ENCRYPTED_FILES.add("Password_Protected-56-hello.ppt");
+ ENCRYPTED_FILES.add("Password_Protected-hello.ppt");
+ }
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ protected static final Map<String,Class<? extends Throwable>> EXCLUDED =
+ new HashMap<>();
+
+ @Parameterized.Parameters(name="{index}: {0}")
+ public static Iterable<Object[]> files() {
+ String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY);
+ if(dataDirName == null) {
+ dataDirName = "test-data";
+ }
+
+ List<Object[]> files = new ArrayList<>();
+ findFile(files, dataDirName + "/slideshow");
+
+ return files;
+ }
+
+ private final PrintStream save = System.out;
+
+ @Before
+ public void setUpBase() throws UnsupportedEncodingException {
+ // set a higher max allocation limit as some test-files require more
+ IOUtils.setByteArrayMaxOverride(5*1024*1024);
+
+ // redirect standard out during the test to avoid spamming the console
with output
+ System.setOut(new PrintStream(NULL_OUTPUT_STREAM, true,
LocaleUtil.CHARSET_1252.name()));
+ }
+
+ @After
+ public void tearDownBase() {
+ System.setOut(save);
+
+ // reset
+ IOUtils.setByteArrayMaxOverride(-1);
+ }
+
+ private static void findFile(List<Object[]> list, String dir) {
+ String[] files = new File(dir).list((arg0, arg1) ->
arg1.toLowerCase(Locale.ROOT).endsWith(".ppt"));
+
+ assertNotNull("Did not find any ppt files in directory " + dir, files);
+
+ for(String file : files) {
+ list.add(new Object[] { new File(dir, file) });
+ }
+ }
+
+ @Parameterized.Parameter
+ public File file;
+
+ @Test
+ public void testAllFiles() throws Exception {
+ String fileName = file.getName();
+ if (EXCLUDED.containsKey(fileName)) {
+ thrown.expect(EXCLUDED.get(fileName));
+ }
+
+ try {
+ runOneFile(file);
+ } catch (OldPowerPointFormatException e) {
+ // expected for some files
+ if(!OLD_FILES.contains(file.getName())) {
+ throw e;
+ }
+ } catch (EncryptedPowerPointFileException e) {
+ // expected for some files
+ if(!ENCRYPTED_FILES.contains(file.getName())) {
+ throw e;
+ }
+ }
+ }
+
+ abstract void runOneFile(File pFile) throws Exception;
+}
Added:
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestPPDrawingTextListing.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestPPDrawingTextListing.java?rev=1849765&view=auto
==============================================================================
---
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestPPDrawingTextListing.java
(added)
+++
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestPPDrawingTextListing.java
Wed Dec 26 13:28:32 2018
@@ -0,0 +1,44 @@
+/* ====================================================================
+ 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.hslf.dev;
+
+import org.apache.poi.EmptyFileException;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.junit.Assert.fail;
+
+public class TestPPDrawingTextListing extends BasePPTIteratingTest {
+ @Test
+ public void testMain() throws IOException {
+ // calls System.exit(): PPDrawingTextListing.main(new String[0]);
+
+ try {
+ PPDrawingTextListing.main(new String[]{"invalidfile"});
+ fail("Should catch exception here");
+ } catch (EmptyFileException e) {
+ // expected here
+ }
+ }
+
+ @Override
+ void runOneFile(File pFile) throws Exception {
+ PPDrawingTextListing.main(new String[]{pFile.getAbsolutePath()});
+ }
+}
Added:
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestPPTXMLDump.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestPPTXMLDump.java?rev=1849765&view=auto
==============================================================================
---
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestPPTXMLDump.java
(added)
+++
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestPPTXMLDump.java
Wed Dec 26 13:28:32 2018
@@ -0,0 +1,49 @@
+/* ====================================================================
+ 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.hslf.dev;
+
+import org.apache.poi.EmptyFileException;
+import org.apache.poi.hslf.HSLFTestDataSamples;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.fail;
+
+public class TestPPTXMLDump extends BasePPTIteratingTest {
+ @Test
+ public void testMain() throws Exception {
+ PPTXMLDump.main(new String[0]);
+
+ PPTXMLDump.main(new String[]{
+
HSLFTestDataSamples.getSampleFile("slide_master.ppt").getAbsolutePath(),
+
HSLFTestDataSamples.getSampleFile("pictures.ppt").getAbsolutePath()
+ });
+
+ try {
+ PPTXMLDump.main(new String[]{"invalidfile"});
+ fail("Should catch exception here");
+ } catch (EmptyFileException e) {
+ // expected here
+ }
+ }
+
+ @Override
+ void runOneFile(File pFile) throws Exception {
+ PPTXMLDump.main(new String[]{pFile.getAbsolutePath()});
+ }
+}
Added:
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSLWTListing.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSLWTListing.java?rev=1849765&view=auto
==============================================================================
---
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSLWTListing.java
(added)
+++
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSLWTListing.java
Wed Dec 26 13:28:32 2018
@@ -0,0 +1,43 @@
+/* ====================================================================
+ 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.hslf.dev;
+
+import org.apache.poi.EmptyFileException;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.junit.Assert.fail;
+
+public class TestSLWTListing extends BasePPTIteratingTest {
+ @Test
+ public void testMain() throws IOException {
+ // calls System.exit(): SLWTListing.main(new String[0]);
+ try {
+ SLWTListing.main(new String[]{"invalidfile"});
+ fail("Should catch exception here");
+ } catch (EmptyFileException e) {
+ // expected here
+ }
+ }
+
+ @Override
+ void runOneFile(File pFile) throws Exception {
+ SLWTListing.main(new String[]{pFile.getAbsolutePath()});
+ }
+}
\ No newline at end of file
Added:
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSLWTTextListing.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSLWTTextListing.java?rev=1849765&view=auto
==============================================================================
---
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSLWTTextListing.java
(added)
+++
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSLWTTextListing.java
Wed Dec 26 13:28:32 2018
@@ -0,0 +1,44 @@
+/* ====================================================================
+ 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.hslf.dev;
+
+import org.apache.poi.EmptyFileException;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.junit.Assert.fail;
+
+public class TestSLWTTextListing extends BasePPTIteratingTest {
+ @Test
+ public void testMain() throws IOException {
+ // calls System.exit(): SLWTTextListing.main(new String[0]);
+
+ try {
+ SLWTTextListing.main(new String[]{"invalidfile"});
+ fail("Should catch exception here");
+ } catch (EmptyFileException e) {
+ // expected here
+ }
+ }
+
+ @Override
+ void runOneFile(File pFile) throws Exception {
+ SLWTTextListing.main(new String[]{pFile.getAbsolutePath()});
+ }
+}
\ No newline at end of file
Added:
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideAndNotesAtomListing.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideAndNotesAtomListing.java?rev=1849765&view=auto
==============================================================================
---
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideAndNotesAtomListing.java
(added)
+++
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideAndNotesAtomListing.java
Wed Dec 26 13:28:32 2018
@@ -0,0 +1,48 @@
+/* ====================================================================
+ 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.hslf.dev;
+
+import org.apache.poi.EmptyFileException;
+import org.apache.poi.hslf.HSLFTestDataSamples;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.junit.Assert.fail;
+
+public class TestSlideAndNotesAtomListing extends BasePPTIteratingTest {
+ @Test
+ public void testMain() throws IOException {
+ // calls System.exit(): SlideAndNotesAtomListing.main(new String[0]);
+ SlideAndNotesAtomListing.main(new String[] {
+
HSLFTestDataSamples.getSampleFile("slide_master.ppt").getAbsolutePath()
+ });
+
+ try {
+ SlideAndNotesAtomListing.main(new String[]{"invalidfile"});
+ fail("Should catch exception here");
+ } catch (EmptyFileException e) {
+ // expected here
+ }
+ }
+
+ @Override
+ void runOneFile(File pFile) throws Exception {
+ SlideAndNotesAtomListing.main(new String[]{pFile.getAbsolutePath()});
+ }
+}
\ No newline at end of file
Added:
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideIdListing.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideIdListing.java?rev=1849765&view=auto
==============================================================================
---
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideIdListing.java
(added)
+++
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideIdListing.java
Wed Dec 26 13:28:32 2018
@@ -0,0 +1,48 @@
+/* ====================================================================
+ 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.hslf.dev;
+
+import org.apache.poi.EmptyFileException;
+import org.apache.poi.hslf.HSLFTestDataSamples;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.junit.Assert.fail;
+
+public class TestSlideIdListing extends BasePPTIteratingTest {
+ @Test
+ public void testMain() throws IOException {
+ // calls System.exit(): SlideIdListing.main(new String[0]);
+ SlideIdListing.main(new String[] {
+
HSLFTestDataSamples.getSampleFile("slide_master.ppt").getAbsolutePath()
+ });
+
+ try {
+ SlideIdListing.main(new String[]{"invalidfile"});
+ fail("Should catch exception here");
+ } catch (EmptyFileException e) {
+ // expected here
+ }
+ }
+
+ @Override
+ void runOneFile(File pFile) throws Exception {
+ SlideIdListing.main(new String[]{pFile.getAbsolutePath()});
+ }
+}
\ No newline at end of file
Added:
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideShowDumper.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideShowDumper.java?rev=1849765&view=auto
==============================================================================
---
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideShowDumper.java
(added)
+++
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideShowDumper.java
Wed Dec 26 13:28:32 2018
@@ -0,0 +1,79 @@
+/* ====================================================================
+ 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.hslf.dev;
+
+import org.apache.poi.EmptyFileException;
+import org.apache.poi.hslf.HSLFTestDataSamples;
+import org.apache.poi.util.IOUtils;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.junit.Assert.fail;
+
+public class TestSlideShowDumper extends BasePPTIteratingTest {
+ private static final Set<String> FAILING = new HashSet<>();
+ static {
+ FAILING.add("cryptoapi-proc2356.ppt");
+ FAILING.add("41384.ppt");
+ FAILING.add("bug56240.ppt");
+ }
+
+ @Test
+ public void testMain() throws IOException {
+ SlideShowDumper.main(new String[0]);
+
+ // SlideShowDumper calls IOUtils.toByteArray(is), which would fail if
a different size is defined
+ IOUtils.setByteArrayMaxOverride(-1);
+
+ SlideShowDumper.main(new String[] {
+
HSLFTestDataSamples.getSampleFile("slide_master.ppt").getAbsolutePath(),
+
HSLFTestDataSamples.getSampleFile("pictures.ppt").getAbsolutePath()
+ });
+
+ try {
+ SlideShowDumper.main(new String[]{"invalidfile"});
+ fail("Should catch exception here");
+ } catch (EmptyFileException e) {
+ // expected here
+ }
+ }
+
+ @Override
+ void runOneFile(File pFile) throws Exception {
+ try {
+ // SlideShowDumper calls IOUtils.toByteArray(is), which would fail
if a different size is defined
+ IOUtils.setByteArrayMaxOverride(-1);
+
+ SlideShowDumper.main(new String[]{pFile.getAbsolutePath()});
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // some corrupted documents currently can cause this excpetion
+ if (!FAILING.contains(pFile.getName()) &&
!ENCRYPTED_FILES.contains(pFile.getName())) {
+ throw e;
+ }
+ } catch (FileNotFoundException e) {
+ // some old files are not detected correctly
+ if(!OLD_FILES.contains(pFile.getName())) {
+ throw e;
+ }
+ }
+ }
+}
\ No newline at end of file
Added:
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideShowRecordDumper.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideShowRecordDumper.java?rev=1849765&view=auto
==============================================================================
---
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideShowRecordDumper.java
(added)
+++
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestSlideShowRecordDumper.java
Wed Dec 26 13:28:32 2018
@@ -0,0 +1,59 @@
+/* ====================================================================
+ 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.hslf.dev;
+
+import org.apache.poi.EmptyFileException;
+import org.apache.poi.hslf.HSLFTestDataSamples;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.junit.Assert.fail;
+
+public class TestSlideShowRecordDumper extends BasePPTIteratingTest {
+ @Test
+ public void testMain() throws IOException {
+ SlideShowRecordDumper.main(new String[0]);
+
+ SlideShowRecordDumper.main(new String[] {
+
HSLFTestDataSamples.getSampleFile("slide_master.ppt").getAbsolutePath(),
+ });
+
+ SlideShowRecordDumper.main(new String[] {
+ "-escher",
+
HSLFTestDataSamples.getSampleFile("slide_master.ppt").getAbsolutePath(),
+ });
+
+ SlideShowRecordDumper.main(new String[] {
+ "-verbose",
+
HSLFTestDataSamples.getSampleFile("pictures.ppt").getAbsolutePath()
+ });
+
+ try {
+ SlideShowRecordDumper.main(new String[]{"invalidfile"});
+ fail("Should catch exception here");
+ } catch (EmptyFileException e) {
+ // expected here
+ }
+ }
+
+ @Override
+ void runOneFile(File pFile) throws Exception {
+ SlideShowRecordDumper.main(new String[]{pFile.getAbsolutePath()});
+ }
+}
\ No newline at end of file
Added:
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestTextStyleListing.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestTextStyleListing.java?rev=1849765&view=auto
==============================================================================
---
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestTextStyleListing.java
(added)
+++
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestTextStyleListing.java
Wed Dec 26 13:28:32 2018
@@ -0,0 +1,57 @@
+/* ====================================================================
+ 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.hslf.dev;
+
+import org.apache.poi.EmptyFileException;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.junit.Assert.fail;
+
+public class TestTextStyleListing extends BasePPTIteratingTest {
+ private static Set<String> FAILING = new HashSet<>();
+ static {
+ FAILING.add("empty_textbox.ppt");
+ }
+
+ @Test
+ public void testMain() throws IOException {
+ // calls System.exit(): TextStyleListing.main(new String[0]);
+ try {
+ TextStyleListing.main(new String[]{"invalidfile"});
+ fail("Should catch exception here");
+ } catch (EmptyFileException e) {
+ // expected here
+ }
+ }
+
+ @Override
+ void runOneFile(File pFile) throws Exception {
+ try {
+ TextStyleListing.main(new String[]{pFile.getAbsolutePath()});
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // some corrupted documents currently can cause this excpetion
+ if (!FAILING.contains(pFile.getName())) {
+ throw e;
+ }
+ }
+ }
+}
\ No newline at end of file
Added:
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestUserEditAndPersistListing.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestUserEditAndPersistListing.java?rev=1849765&view=auto
==============================================================================
---
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestUserEditAndPersistListing.java
(added)
+++
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/dev/TestUserEditAndPersistListing.java
Wed Dec 26 13:28:32 2018
@@ -0,0 +1,44 @@
+/* ====================================================================
+ 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.hslf.dev;
+
+import org.apache.poi.EmptyFileException;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.junit.Assert.fail;
+
+public class TestUserEditAndPersistListing extends BasePPTIteratingTest {
+ @Test
+ public void testMain() throws IOException {
+ // calls System.exit(): UserEditAndPersistListing.main(new String[0]);
+
+ try {
+ UserEditAndPersistListing.main(new String[]{"invalidfile"});
+ fail("Should catch exception here");
+ } catch (EmptyFileException e) {
+ // expected here
+ }
+ }
+
+ @Override
+ void runOneFile(File pFile) throws Exception {
+ UserEditAndPersistListing.main(new String[]{pFile.getAbsolutePath()});
+ }
+}
\ No newline at end of file
Modified: poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherDump.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherDump.java?rev=1849765&r1=1849764&r2=1849765&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherDump.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherDump.java Wed Dec 26
13:28:32 2018
@@ -52,7 +52,7 @@ public class TestEscherDump {
@Test
public void testWithData() throws Exception {
- new EscherDump().dumpOld(8, new ByteArrayInputStream(new byte[] { 00,
00, 00, 00, 00, 00, 00, 00 }), nullPS);
+ new EscherDump().dumpOld(8, new ByteArrayInputStream(new byte[] {0, 0,
0, 0, 0, 0, 0, 0}), nullPS);
}
@Test
@@ -63,14 +63,11 @@ public class TestEscherDump {
//new EscherDump().dumpOld(data.length, new
ByteArrayInputStream(data), System.out);
data = new byte[2586114];
- InputStream stream =
HSSFTestDataSamples.openSampleFileStream("44593.xls");
- try {
+ try (InputStream stream =
HSSFTestDataSamples.openSampleFileStream("44593.xls")) {
int bytes = IOUtils.readFully(stream, data);
assertTrue(bytes != -1);
//new EscherDump().dump(bytes, data, System.out);
//new EscherDump().dumpOld(bytes, new ByteArrayInputStream(data),
System.out);
- } finally {
- stream.close();
}
}
Modified:
poi/trunk/src/testcases/org/apache/poi/hssf/dev/BaseXLSIteratingTest.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/dev/BaseXLSIteratingTest.java?rev=1849765&r1=1849764&r2=1849765&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/dev/BaseXLSIteratingTest.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/dev/BaseXLSIteratingTest.java
Wed Dec 26 13:28:32 2018
@@ -20,7 +20,6 @@ import static org.junit.Assert.assertNot
import java.io.File;
import java.io.FileInputStream;
-import java.io.FilenameFilter;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
@@ -29,7 +28,6 @@ import java.util.Locale;
import java.util.Map;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.NullOutputStream;
import org.junit.Rule;
@@ -71,12 +69,7 @@ public abstract class BaseXLSIteratingTe
}
private static void findFile(List<Object[]> list, String dir) {
- String[] files = new File(dir).list(new FilenameFilter() {
- @Override
- public boolean accept(File arg0, String arg1) {
- return arg1.toLowerCase(Locale.ROOT).endsWith(".xls");
- }
- });
+ String[] files = new File(dir).list((arg0, arg1) ->
arg1.toLowerCase(Locale.ROOT).endsWith(".xls"));
assertNotNull("Did not find any xls files in directory " + dir, files);
@@ -99,17 +92,9 @@ public abstract class BaseXLSIteratingTe
runOneFile(file);
} catch (Exception e) {
// try to read it in HSSFWorkbook to quickly fail if we
cannot read the file there at all and thus probably should use EXCLUDED instead
- FileInputStream stream = new FileInputStream(file);
- HSSFWorkbook wb = null;
- try {
- wb = new HSSFWorkbook(stream);
- assertNotNull(wb);
- } finally {
- if (wb != null) {
- wb.close();
- }
- stream.close();
- }
+ try (FileInputStream stream = new FileInputStream(file);
HSSFWorkbook wb = new HSSFWorkbook(stream)) {
+ assertNotNull(wb);
+ }
throw e;
}
Modified:
poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java?rev=1849765&r1=1849764&r2=1849765&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java
Wed Dec 26 13:28:32 2018
@@ -43,7 +43,6 @@ public class TestBiffDrawingToXml extend
EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class); //
Biff 5 / Excel 5
EXCLUDED.put("60284.xls", OldExcelFormatException.class); // Biff 5 /
Excel 5
EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); //
Biff 5 / Excel 95
- EXCLUDED.put("60284.xls", OldExcelFormatException.class); // Biff 5 /
Excel 95
EXCLUDED.put("43493.xls",
RecordInputStream.LeftoverDataException.class); // HSSFWorkbook cannot open it
as well
EXCLUDED.put("44958_1.xls",
RecordInputStream.LeftoverDataException.class);
EXCLUDED.put("61300.xls", RecordFormatException.class);
@@ -55,12 +54,9 @@ public class TestBiffDrawingToXml extend
try {
//System.setOut(new
PrintStream(TestBiffViewer.NULL_OUTPUT_STREAM));
// use a NullOutputStream to not write the bytes
anywhere for best runtime
- InputStream wb = new FileInputStream(pFile);
- try {
- BiffDrawingToXml.writeToFile(NULL_OUTPUT_STREAM, wb,
false, new String[] {});
- } finally {
- wb.close();
- }
+ try (InputStream wb = new FileInputStream(pFile)) {
+ BiffDrawingToXml.writeToFile(NULL_OUTPUT_STREAM, wb, false,
new String[]{});
+ }
} finally {
System.setOut(save);
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java?rev=1849765&r1=1849764&r2=1849765&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java Wed
Dec 26 13:28:32 2018
@@ -43,7 +43,6 @@ public class TestEFBiffViewer extends Ba
EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class); //
Biff 5 / Excel 5
EXCLUDED.put("60284.xls", OldExcelFormatException.class); // Biff 5 /
Excel 5
EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); //
Biff 5 / Excel 95
- EXCLUDED.put("60284.xls", OldExcelFormatException.class); // Biff 5 /
Excel 95
EXCLUDED.put("43493.xls",
RecordInputStream.LeftoverDataException.class); // HSSFWorkbook cannot open it
as well
EXCLUDED.put("44958_1.xls",
RecordInputStream.LeftoverDataException.class);
EXCLUDED.put("XRefCalc.xls", RuntimeException.class); //
"Buffer overrun"
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java?rev=1849765&r1=1849764&r2=1849765&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java Wed
Dec 26 13:28:32 2018
@@ -44,7 +44,6 @@ public class TestFormulaViewer extends B
EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class); //
Biff 5 / Excel 5
EXCLUDED.put("60284.xls", OldExcelFormatException.class); // Biff 5 /
Excel 5
EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); //
Biff 5 / Excel 95
- EXCLUDED.put("60284.xls", OldExcelFormatException.class); // Biff 5 /
Excel 95
EXCLUDED.put("43493.xls",
RecordInputStream.LeftoverDataException.class); // HSSFWorkbook cannot open it
as well
EXCLUDED.put("44958_1.xls",
RecordInputStream.LeftoverDataException.class);
EXCLUDED.put("61300.xls", RecordFormatException.class);
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestReSave.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestReSave.java?rev=1849765&r1=1849764&r2=1849765&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestReSave.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestReSave.java Wed Dec 26
13:28:32 2018
@@ -47,7 +47,6 @@ public class TestReSave extends BaseXLSI
EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class); //
Biff 5 / Excel 5
EXCLUDED.put("60284.xls", OldExcelFormatException.class); // Biff 5 /
Excel 5
EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); //
Biff 5 / Excel 95
- EXCLUDED.put("60284.xls", OldExcelFormatException.class); // Biff 5 /
Excel 95
EXCLUDED.put("43493.xls",
RecordInputStream.LeftoverDataException.class); // HSSFWorkbook cannot open it
as well
EXCLUDED.put("44958_1.xls",
RecordInputStream.LeftoverDataException.class);
EXCLUDED.put("XRefCalc.xls", RuntimeException.class); //
"Buffer overrun"
@@ -79,7 +78,6 @@ public class TestReSave extends BaseXLSI
// clean up the re-saved file
assertTrue(!reSavedFile.exists() ||
reSavedFile.delete());
}
-
} finally {
System.setOut(save);
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java?rev=1849765&r1=1849764&r2=1849765&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java Wed
Dec 26 13:28:32 2018
@@ -37,7 +37,6 @@ public class TestRecordLister extends Ba
EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class); //
Biff 5 / Excel 5
EXCLUDED.put("60284.xls", OldExcelFormatException.class); // Biff 5 /
Excel 5
EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); //
Biff 5 / Excel 95
- EXCLUDED.put("60284.xls", OldExcelFormatException.class); // Biff 5 /
Excel 95
EXCLUDED.put("61300.xls", RecordFormatException.class);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]