]> source.dussan.org Git - poi.git/commitdiff
renamed macro-enabled test files to have the correct extentions
authorYegor Kozlov <yegor@apache.org>
Fri, 14 Aug 2009 17:27:12 +0000 (17:27 +0000)
committerYegor Kozlov <yegor@apache.org>
Fri, 14 Aug 2009 17:27:12 +0000 (17:27 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@804305 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/TestEmbeded.java
src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java
src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java
src/ooxml/testcases/org/apache/poi/ooxml/data/ExcelWithAttachments.xlsm [new file with mode: 0644]
src/ooxml/testcases/org/apache/poi/ooxml/data/ExcelWithAttachments.xlsx [deleted file]
src/ooxml/testcases/org/apache/poi/ooxml/data/PPTWithAttachments.pptm [new file with mode: 0644]
src/ooxml/testcases/org/apache/poi/ooxml/data/PPTWithAttachments.pptx [deleted file]

index ff97d0329dd64043c33fed4f36e8b976970c0532..ddd394cf2d5e3de5ad6ab7fe8ff6be1d99d26f66 100644 (file)
@@ -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()));
index 701641111de3eff38fcff189b80a9f8909b21240..e6644a5634814b1934bd9e520e2192d8b31e6b0d 100755 (executable)
@@ -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<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 {
 
         OPCPackage pkg1 = OPCPackage.open(path);
         OPCParser doc = new OPCParser(pkg1);
         doc.parse(new TestFactory());
 
+        HashMap<String,POIXMLDocumentPart> context = new HashMap<String,POIXMLDocumentPart>();
+        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<String,POIXMLDocumentPart>();
+        traverse(doc, context);
+        context.clear();
+
         assertEquals(pkg1.getRelationships().size(), pkg2.getRelationships().size());
 
         ArrayList<PackagePart> 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());
     }
 
index 90a73292715ddbbc18aaaeb9aeed443190e218a2..aa854944914034aa4ae875214b760609b548d8fe 100644 (file)
@@ -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.xlsm b/src/ooxml/testcases/org/apache/poi/ooxml/data/ExcelWithAttachments.xlsm
new file mode 100644 (file)
index 0000000..cb3e564
Binary files /dev/null and b/src/ooxml/testcases/org/apache/poi/ooxml/data/ExcelWithAttachments.xlsm differ
diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/data/ExcelWithAttachments.xlsx b/src/ooxml/testcases/org/apache/poi/ooxml/data/ExcelWithAttachments.xlsx
deleted file mode 100644 (file)
index cb3e564..0000000
Binary files a/src/ooxml/testcases/org/apache/poi/ooxml/data/ExcelWithAttachments.xlsx and /dev/null differ
diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/data/PPTWithAttachments.pptm b/src/ooxml/testcases/org/apache/poi/ooxml/data/PPTWithAttachments.pptm
new file mode 100644 (file)
index 0000000..00b148d
Binary files /dev/null and b/src/ooxml/testcases/org/apache/poi/ooxml/data/PPTWithAttachments.pptm differ
diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/data/PPTWithAttachments.pptx b/src/ooxml/testcases/org/apache/poi/ooxml/data/PPTWithAttachments.pptx
deleted file mode 100644 (file)
index 00b148d..0000000
Binary files a/src/ooxml/testcases/org/apache/poi/ooxml/data/PPTWithAttachments.pptx and /dev/null differ