renamed macro-enabled test files to have the correct extentions

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@804305 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2009-08-14 17:27:12 +00:00
parent 6fab98df5b
commit ed16c25a9a
5 changed files with 34 additions and 12 deletions

View File

@ -44,7 +44,7 @@ public class TestEmbeded extends TestCase
} }
public void testExcel() throws Exception { public void testExcel() throws Exception {
File f = new File(dirname, "ExcelWithAttachments.xlsx"); File f = new File(dirname, "ExcelWithAttachments.xlsm");
assertTrue(f.exists()); assertTrue(f.exists());
POIXMLDocument doc = new XSSFWorkbook(OPCPackage.open(f.toString())); POIXMLDocument doc = new XSSFWorkbook(OPCPackage.open(f.toString()));
@ -60,7 +60,7 @@ public class TestEmbeded extends TestCase
} }
public void testPowerPoint() throws Exception { public void testPowerPoint() throws Exception {
File f = new File(dirname, "PPTWithAttachments.pptx"); File f = new File(dirname, "PPTWithAttachments.pptm");
assertTrue(f.exists()); assertTrue(f.exists());
POIXMLDocument doc = new XSLFSlideShow(OPCPackage.open(f.toString())); POIXMLDocument doc = new XSLFSlideShow(OPCPackage.open(f.toString()));

View File

@ -24,12 +24,9 @@ import java.io.IOException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.TempFile; import org.apache.poi.util.TempFile;
import org.apache.poi.xslf.XSLFSlideShow;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.PackageRelationship;
@ -69,12 +66,32 @@ public class TestPOIXMLDocument extends TestCase
} }
/**
* Recursively traverse a OOXML document and assert that same logical parts have the same physical instances
*/
private static void traverse(POIXMLDocumentPart part, HashMap<String,POIXMLDocumentPart> context) throws IOException{
context.put(part.getPackageRelationship().getTargetURI().toString(), part);
for(POIXMLDocumentPart p : part.getRelations()){
String uri = p.getPackageRelationship().getTargetURI().toString();
if (!context.containsKey(uri)) {
traverse(p, context);
} else {
POIXMLDocumentPart prev = context.get(uri);
assertSame("Duplicate POIXMLDocumentPart instance for targetURI=" + uri, prev, p);
}
}
}
public void assertReadWrite(String path) throws Exception { public void assertReadWrite(String path) throws Exception {
OPCPackage pkg1 = OPCPackage.open(path); OPCPackage pkg1 = OPCPackage.open(path);
OPCParser doc = new OPCParser(pkg1); OPCParser doc = new OPCParser(pkg1);
doc.parse(new TestFactory()); doc.parse(new TestFactory());
HashMap<String,POIXMLDocumentPart> context = new HashMap<String,POIXMLDocumentPart>();
traverse(doc, context);
context.clear();
File tmp = TempFile.createTempFile("poi-ooxml", ".tmp"); File tmp = TempFile.createTempFile("poi-ooxml", ".tmp");
FileOutputStream out = new FileOutputStream(tmp); FileOutputStream out = new FileOutputStream(tmp);
doc.write(out); doc.write(out);
@ -82,6 +99,12 @@ public class TestPOIXMLDocument extends TestCase
OPCPackage pkg2 = OPCPackage.open(tmp.getAbsolutePath()); OPCPackage pkg2 = OPCPackage.open(tmp.getAbsolutePath());
doc = new OPCParser(pkg1);
doc.parse(new TestFactory());
context = new HashMap<String,POIXMLDocumentPart>();
traverse(doc, context);
context.clear();
assertEquals(pkg1.getRelationships().size(), pkg2.getRelationships().size()); assertEquals(pkg1.getRelationships().size(), pkg2.getRelationships().size());
ArrayList<PackagePart> l1 = pkg1.getParts(); ArrayList<PackagePart> l1 = pkg1.getParts();
@ -102,12 +125,12 @@ public class TestPOIXMLDocument extends TestCase
} }
public void testPPTX() throws Exception { public void testPPTX() throws Exception {
File file = new File(System.getProperty("OOXML.testdata.path"), "PPTWithAttachments.pptx"); File file = new File(System.getProperty("OOXML.testdata.path"), "PPTWithAttachments.pptm");
assertReadWrite(file.getAbsolutePath()); assertReadWrite(file.getAbsolutePath());
} }
public void testXLSX() throws Exception { public void testXLSX() throws Exception {
File file = new File(System.getProperty("OOXML.testdata.path"), "ExcelWithAttachments.xlsx"); File file = new File(System.getProperty("OOXML.testdata.path"), "ExcelWithAttachments.xlsm");
assertReadWrite(file.getAbsolutePath()); assertReadWrite(file.getAbsolutePath());
} }

View File

@ -34,7 +34,7 @@ public class TestXMLPropertiesTextExtractor extends TestCase {
public void testGetFromMainExtractor() throws Exception { public void testGetFromMainExtractor() throws Exception {
OPCPackage pkg = OPCPackage.open( OPCPackage pkg = OPCPackage.open(
(new File(dirname, "ExcelWithAttachments.xlsx")).toString() (new File(dirname, "ExcelWithAttachments.xlsm")).toString()
); );
XSSFWorkbook wb = new XSSFWorkbook(pkg); XSSFWorkbook wb = new XSSFWorkbook(pkg);
@ -55,7 +55,7 @@ public class TestXMLPropertiesTextExtractor extends TestCase {
public void testCore() throws Exception { public void testCore() throws Exception {
OPCPackage pkg = OPCPackage.open( OPCPackage pkg = OPCPackage.open(
(new File(dirname, "ExcelWithAttachments.xlsx")).toString() (new File(dirname, "ExcelWithAttachments.xlsm")).toString()
); );
XSSFWorkbook wb = new XSSFWorkbook(pkg); XSSFWorkbook wb = new XSSFWorkbook(pkg);
@ -72,7 +72,7 @@ public class TestXMLPropertiesTextExtractor extends TestCase {
public void testExtended() throws Exception { public void testExtended() throws Exception {
OPCPackage pkg = OPCPackage.open( OPCPackage pkg = OPCPackage.open(
(new File(dirname, "ExcelWithAttachments.xlsx")).toString() (new File(dirname, "ExcelWithAttachments.xlsm")).toString()
); );
XSSFWorkbook wb = new XSSFWorkbook(pkg); XSSFWorkbook wb = new XSSFWorkbook(pkg);
@ -82,7 +82,6 @@ public class TestXMLPropertiesTextExtractor extends TestCase {
// Now check // Now check
String text = ext.getText(); String text = ext.getText();
String eText = ext.getExtendedPropertiesText(); String eText = ext.getExtendedPropertiesText();
System.out.println(eText);
assertTrue(text.contains("Application = Microsoft Excel")); assertTrue(text.contains("Application = Microsoft Excel"));
assertTrue(text.contains("Company = Mera")); assertTrue(text.contains("Company = Mera"));