]> source.dussan.org Git - poi.git/commitdiff
bug 52949: prepare for adding DOC/DOCM and PPT/PPTM test cases
authorJaven O'Neal <onealj@apache.org>
Sun, 10 Apr 2016 14:33:47 +0000 (14:33 +0000)
committerJaven O'Neal <onealj@apache.org>
Sun, 10 Apr 2016 14:33:47 +0000 (14:33 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1738438 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java

index ad1f8393e284cfd0dd42a71d77021dd4c695ff63..f44d249f1d3b0960153d95fbb75b89c252ecdf9c 100644 (file)
@@ -49,29 +49,23 @@ public class TestVBAMacroReader {
     }
     
     @Test
-    public void fromStream() throws Exception {
-        VBAMacroReader r;
-        
-        r = new VBAMacroReader(HSSFTestDataSamples.openSampleFileStream("SimpleMacro.xls"));
-        assertMacroContents(r);
-        r.close();
-        
-        r = new VBAMacroReader(HSSFTestDataSamples.openSampleFileStream("SimpleMacro.xlsm"));
-        assertMacroContents(r);
-        r.close();
+    public void HSSFfromStream() throws Exception {
+        fromStream(POIDataSamples.getSpreadSheetInstance(), "SimpleMacro.xls");
     }
     @Test
-    public void fromFile() throws Exception {
-        VBAMacroReader r;
-        
-        r = new VBAMacroReader(HSSFTestDataSamples.getSampleFile("SimpleMacro.xls"));
-        assertMacroContents(r);
-        r.close();
-        
-        r = new VBAMacroReader(HSSFTestDataSamples.getSampleFile("SimpleMacro.xlsm"));
-        assertMacroContents(r);
-        r.close();
+    public void XSSFfromStream() throws Exception {
+        fromStream(POIDataSamples.getSpreadSheetInstance(), "SimpleMacro.xlsm");
     }
+
+    @Test
+    public void HSSFfromFile() throws Exception {
+        fromFile(POIDataSamples.getSpreadSheetInstance(), "SimpleMacro.xls");
+    }
+    @Test
+    public void XSSFfromFile() throws Exception {
+        fromFile(POIDataSamples.getSpreadSheetInstance(), "SimpleMacro.xlsm");
+    }
+
     @Test
     public void fromNPOIFS() throws Exception {
         NPOIFSFileSystem fs = new NPOIFSFileSystem(
@@ -80,6 +74,28 @@ public class TestVBAMacroReader {
         assertMacroContents(r);
         r.close();
     }
+
+    protected void fromFile(POIDataSamples poiDataSamples, String filename) {   
+        File f = poiDataSamples.getSampleFile(filename);
+        VBAMacroReader r = new VBAMacroReader(f);
+        try {
+            assertMacroContents(r);
+        } finally {
+            r.close();
+        }
+    }
+
+    protected void fromStream(POIDataSamples poiDataSamples, String filename) {   
+        InputStream fis = poiDataSamples.openSampleFileStream(filename);
+        try {
+            VBAMacroReader r = new VBAMacroReader(fis);
+            try {
+                assertMacroContents(r);
+            } finally {
+                r.close();
+            }
+        }
+    }
     
     protected void assertMacroContents(VBAMacroReader r) throws Exception {
         Map<String,String> contents = r.readMacros();