Cover some dev-tools with a few simple tests, close resources correctly
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1776798 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c2022f7c3a
commit
13e4ff4553
@ -16,10 +16,7 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.dev;
|
package org.apache.poi.dev;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
@ -34,7 +31,7 @@ import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
|
|||||||
* Useful for seeing what parts are defined, and how
|
* Useful for seeing what parts are defined, and how
|
||||||
* they're all related to each other.
|
* they're all related to each other.
|
||||||
*/
|
*/
|
||||||
public class OOXMLLister {
|
public class OOXMLLister implements Closeable {
|
||||||
private final OPCPackage container;
|
private final OPCPackage container;
|
||||||
private final PrintStream disp;
|
private final PrintStream disp;
|
||||||
|
|
||||||
@ -110,6 +107,7 @@ public class OOXMLLister {
|
|||||||
displayRelation(rel, "");
|
displayRelation(rel, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayRelation(PackageRelationship rel, String indent) {
|
private void displayRelation(PackageRelationship rel, String indent) {
|
||||||
disp.println(indent+"Relationship:");
|
disp.println(indent+"Relationship:");
|
||||||
disp.println(indent+"\tFrom: "+ rel.getSourceURI());
|
disp.println(indent+"\tFrom: "+ rel.getSourceURI());
|
||||||
@ -119,6 +117,11 @@ public class OOXMLLister {
|
|||||||
disp.println(indent+"\tType: " + rel.getRelationshipType());
|
disp.println(indent+"\tType: " + rel.getRelationshipType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
container.close();
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
if(args.length == 0) {
|
if(args.length == 0) {
|
||||||
System.err.println("Use:");
|
System.err.println("Use:");
|
||||||
@ -137,9 +140,13 @@ public class OOXMLLister {
|
|||||||
OPCPackage.open(f.toString(), PackageAccess.READ)
|
OPCPackage.open(f.toString(), PackageAccess.READ)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
lister.disp.println(f.toString() + "\n");
|
lister.disp.println(f.toString() + "\n");
|
||||||
lister.displayParts();
|
lister.displayParts();
|
||||||
lister.disp.println();
|
lister.disp.println();
|
||||||
lister.displayRelations();
|
lister.displayRelations();
|
||||||
|
} finally {
|
||||||
|
lister.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
src/ooxml/testcases/org/apache/poi/dev/TestOOXMLLister.java
Normal file
27
src/ooxml/testcases/org/apache/poi/dev/TestOOXMLLister.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package org.apache.poi.dev;
|
||||||
|
|
||||||
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
|
import org.apache.poi.openxml4j.opc.PackageAccess;
|
||||||
|
import org.apache.poi.util.NullOutputStream;
|
||||||
|
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
|
||||||
|
public class TestOOXMLLister {
|
||||||
|
@Test
|
||||||
|
public void testMain() throws Exception {
|
||||||
|
File file = XSSFTestDataSamples.getSampleFile("Formatting.xlsx");
|
||||||
|
OOXMLLister.main(new String[] {file.getAbsolutePath()});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithPrintStream() throws Exception {
|
||||||
|
File file = XSSFTestDataSamples.getSampleFile("Formatting.xlsx");
|
||||||
|
OOXMLLister lister = new OOXMLLister(OPCPackage.open(file.getAbsolutePath(), PackageAccess.READ), new PrintStream(new NullOutputStream()));
|
||||||
|
lister.displayParts();
|
||||||
|
lister.displayRelations();
|
||||||
|
lister.close();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package org.apache.poi.dev;
|
||||||
|
|
||||||
|
import org.apache.poi.util.TempFile;
|
||||||
|
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class TestOOXMLPrettyPrint {
|
||||||
|
@Test
|
||||||
|
public void testMain() throws Exception {
|
||||||
|
File file = XSSFTestDataSamples.getSampleFile("Formatting.xlsx");
|
||||||
|
File outFile = TempFile.createTempFile("Formatting", "-pretty.xlsx");
|
||||||
|
|
||||||
|
assertTrue(outFile.delete());
|
||||||
|
assertFalse(outFile.exists());
|
||||||
|
|
||||||
|
OOXMLPrettyPrint.main(new String[] {
|
||||||
|
file.getAbsolutePath(), outFile.getAbsolutePath()
|
||||||
|
});
|
||||||
|
|
||||||
|
assertTrue(outFile.exists());
|
||||||
|
assertTrue(outFile.delete());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package org.apache.poi.dev;
|
||||||
|
|
||||||
|
import org.apache.poi.util.TempFile;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class TestRecordGenerator {
|
||||||
|
@Ignore("Could not get this to run, probably the dev-application does not work any more at all")
|
||||||
|
@Test
|
||||||
|
public void testNotEnoughArgs() throws Exception {
|
||||||
|
RecordGenerator.main(new String[] {});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Ignore("Could not get this to run, probably the dev-application does not work any more at all")
|
||||||
|
@Test
|
||||||
|
public void testMainRecords() throws Exception {
|
||||||
|
File dir = TempFile.createTempDirectory("TestRecordGenerator");
|
||||||
|
|
||||||
|
RecordGenerator.main(new String[] {
|
||||||
|
"src/records/definitions/",
|
||||||
|
"src/records/styles/",
|
||||||
|
dir.getAbsolutePath(),
|
||||||
|
dir.getAbsolutePath(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Ignore("Could not get this to run, probably the dev-application does not work any more at all")
|
||||||
|
@Test
|
||||||
|
public void testMainTypes() throws Exception {
|
||||||
|
File dir = TempFile.createTempDirectory("TestRecordGenerator");
|
||||||
|
|
||||||
|
RecordGenerator.main(new String[] {
|
||||||
|
"src/types/definitions/",
|
||||||
|
"src/types/styles/",
|
||||||
|
dir.getAbsolutePath(),
|
||||||
|
dir.getAbsolutePath(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -52,15 +52,17 @@ public final class VSDDumper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NPOIFSFileSystem poifs = new NPOIFSFileSystem(new File(args[0]));
|
NPOIFSFileSystem poifs = new NPOIFSFileSystem(new File(args[0]));
|
||||||
|
try {
|
||||||
HDGFDiagram hdgf = new HDGFDiagram(poifs);
|
HDGFDiagram hdgf = new HDGFDiagram(poifs);
|
||||||
|
|
||||||
PrintStream ps = System.out;
|
PrintStream ps = System.out;
|
||||||
ps.println("Opened " + args[0]);
|
ps.println("Opened " + args[0]);
|
||||||
VSDDumper vd = new VSDDumper(ps, hdgf);
|
VSDDumper vd = new VSDDumper(ps, hdgf);
|
||||||
vd.dumpFile();
|
vd.dumpFile();
|
||||||
|
} finally {
|
||||||
poifs.close();
|
poifs.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void dumpFile() {
|
public void dumpFile() {
|
||||||
dumpVal("Claimed document size", hdgf.getDocumentSize(), 0);
|
dumpVal("Claimed document size", hdgf.getDocumentSize(), 0);
|
||||||
|
@ -41,17 +41,20 @@ public final class HMEFDumper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean truncatePropData = true;
|
boolean truncatePropData = true;
|
||||||
for(int i=0; i<args.length; i++) {
|
for (String arg : args) {
|
||||||
if(args[i].equalsIgnoreCase("--full")) {
|
if (arg.equalsIgnoreCase("--full")) {
|
||||||
truncatePropData = false;
|
truncatePropData = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
HMEFDumper dumper = new HMEFDumper(
|
InputStream stream = new FileInputStream(arg);
|
||||||
new FileInputStream(args[i])
|
try {
|
||||||
);
|
HMEFDumper dumper = new HMEFDumper(stream);
|
||||||
dumper.setTruncatePropertyData(truncatePropData);
|
dumper.setTruncatePropertyData(truncatePropData);
|
||||||
dumper.dump();
|
dumper.dump();
|
||||||
|
} finally {
|
||||||
|
stream.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package org.apache.poi.hdgf.dev;
|
||||||
|
|
||||||
|
import org.apache.poi.POIDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class TestVSDDumper {
|
||||||
|
@Test
|
||||||
|
public void main() throws Exception {
|
||||||
|
File file = POIDataSamples.getDiagramInstance().getFile("Test_Visio-Some_Random_Text.vsd");
|
||||||
|
VSDDumper.main(new String[] { file.getAbsolutePath() });
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package org.apache.poi.hmef.dev;
|
||||||
|
|
||||||
|
import org.apache.poi.POIDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class TestHMEFDumper {
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void noArguments() throws Exception {
|
||||||
|
HMEFDumper.main(new String[] {});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void main() throws Exception {
|
||||||
|
File file = POIDataSamples.getHMEFInstance().getFile("quick-winmail.dat");
|
||||||
|
HMEFDumper.main(new String[] {
|
||||||
|
file.getAbsolutePath()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mainFull() throws Exception {
|
||||||
|
File file = POIDataSamples.getHMEFInstance().getFile("quick-winmail.dat");
|
||||||
|
HMEFDumper.main(new String[] {
|
||||||
|
"--full",
|
||||||
|
file.getAbsolutePath()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user