From ed16c25a9a31d8b7bce68143fdd6cb75f944e3fc Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Fri, 14 Aug 2009 17:27:12 +0000 Subject: [PATCH] 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 --- .../testcases/org/apache/poi/TestEmbeded.java | 4 +- .../org/apache/poi/TestPOIXMLDocument.java | 35 +++++++++++++++--- .../poi/TestXMLPropertiesTextExtractor.java | 7 ++-- ...chments.xlsx => ExcelWithAttachments.xlsm} | Bin ...tachments.pptx => PPTWithAttachments.pptm} | Bin 5 files changed, 34 insertions(+), 12 deletions(-) rename src/ooxml/testcases/org/apache/poi/ooxml/data/{ExcelWithAttachments.xlsx => ExcelWithAttachments.xlsm} (100%) rename src/ooxml/testcases/org/apache/poi/ooxml/data/{PPTWithAttachments.pptx => PPTWithAttachments.pptm} (100%) diff --git a/src/ooxml/testcases/org/apache/poi/TestEmbeded.java b/src/ooxml/testcases/org/apache/poi/TestEmbeded.java index ff97d0329..ddd394cf2 100644 --- a/src/ooxml/testcases/org/apache/poi/TestEmbeded.java +++ b/src/ooxml/testcases/org/apache/poi/TestEmbeded.java @@ -44,7 +44,7 @@ public class TestEmbeded extends TestCase } public void testExcel() throws Exception { - File f = new File(dirname, "ExcelWithAttachments.xlsx"); + File f = new File(dirname, "ExcelWithAttachments.xlsm"); assertTrue(f.exists()); POIXMLDocument doc = new XSSFWorkbook(OPCPackage.open(f.toString())); @@ -60,7 +60,7 @@ public class TestEmbeded extends TestCase } public void testPowerPoint() throws Exception { - File f = new File(dirname, "PPTWithAttachments.pptx"); + File f = new File(dirname, "PPTWithAttachments.pptm"); assertTrue(f.exists()); POIXMLDocument doc = new XSLFSlideShow(OPCPackage.open(f.toString())); diff --git a/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java b/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java index 701641111..e6644a563 100755 --- a/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java +++ b/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java @@ -24,12 +24,9 @@ import java.io.IOException; import java.io.FileOutputStream; import java.util.List; import java.util.ArrayList; +import java.util.HashMap; -import org.apache.poi.util.IOUtils; 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.PackagePart; 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 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 { OPCPackage pkg1 = OPCPackage.open(path); OPCParser doc = new OPCParser(pkg1); doc.parse(new TestFactory()); + HashMap context = new HashMap(); + traverse(doc, context); + context.clear(); + File tmp = TempFile.createTempFile("poi-ooxml", ".tmp"); FileOutputStream out = new FileOutputStream(tmp); doc.write(out); @@ -82,6 +99,12 @@ public class TestPOIXMLDocument extends TestCase OPCPackage pkg2 = OPCPackage.open(tmp.getAbsolutePath()); + doc = new OPCParser(pkg1); + doc.parse(new TestFactory()); + context = new HashMap(); + traverse(doc, context); + context.clear(); + assertEquals(pkg1.getRelationships().size(), pkg2.getRelationships().size()); ArrayList l1 = pkg1.getParts(); @@ -102,12 +125,12 @@ public class TestPOIXMLDocument extends TestCase } 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()); } 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()); } diff --git a/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java b/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java index 90a732927..aa8549449 100644 --- a/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java @@ -34,7 +34,7 @@ public class TestXMLPropertiesTextExtractor extends TestCase { public void testGetFromMainExtractor() throws Exception { OPCPackage pkg = OPCPackage.open( - (new File(dirname, "ExcelWithAttachments.xlsx")).toString() + (new File(dirname, "ExcelWithAttachments.xlsm")).toString() ); XSSFWorkbook wb = new XSSFWorkbook(pkg); @@ -55,7 +55,7 @@ public class TestXMLPropertiesTextExtractor extends TestCase { public void testCore() throws Exception { OPCPackage pkg = OPCPackage.open( - (new File(dirname, "ExcelWithAttachments.xlsx")).toString() + (new File(dirname, "ExcelWithAttachments.xlsm")).toString() ); XSSFWorkbook wb = new XSSFWorkbook(pkg); @@ -72,7 +72,7 @@ public class TestXMLPropertiesTextExtractor extends TestCase { public void testExtended() throws Exception { OPCPackage pkg = OPCPackage.open( - (new File(dirname, "ExcelWithAttachments.xlsx")).toString() + (new File(dirname, "ExcelWithAttachments.xlsm")).toString() ); XSSFWorkbook wb = new XSSFWorkbook(pkg); @@ -82,7 +82,6 @@ public class TestXMLPropertiesTextExtractor extends TestCase { // Now check String text = ext.getText(); String eText = ext.getExtendedPropertiesText(); - System.out.println(eText); assertTrue(text.contains("Application = Microsoft Excel")); assertTrue(text.contains("Company = Mera")); diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/data/ExcelWithAttachments.xlsx b/src/ooxml/testcases/org/apache/poi/ooxml/data/ExcelWithAttachments.xlsm similarity index 100% rename from src/ooxml/testcases/org/apache/poi/ooxml/data/ExcelWithAttachments.xlsx rename to src/ooxml/testcases/org/apache/poi/ooxml/data/ExcelWithAttachments.xlsm diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/data/PPTWithAttachments.pptx b/src/ooxml/testcases/org/apache/poi/ooxml/data/PPTWithAttachments.pptm similarity index 100% rename from src/ooxml/testcases/org/apache/poi/ooxml/data/PPTWithAttachments.pptx rename to src/ooxml/testcases/org/apache/poi/ooxml/data/PPTWithAttachments.pptm