poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r645483 [2/7] - in /poi/branches/ooxml: ./ src/documentation/content/xdocs/ src/java/org/apache/poi/hssf/record/ src/java/org/apache/poi/hssf/record/cf/ src/java/org/apache/poi/hssf/usermodel/ src/java/org/apache/poi/util/ src/testcases/org...
Date Mon, 07 Apr 2008 12:52:00 GMT
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java Mon
Apr  7 05:51:50 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,51 +14,47 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record;
 
-import org.apache.poi.util.HexRead;
-import org.apache.poi.util.IntMapper;
-import org.apache.poi.hssf.record.TestcaseRecordInputStream;
-
-import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.util.HexRead;
+import org.apache.poi.util.IntMapper;
+
 /**
  * Exercise the SSTDeserializer class.
  *
  * @author Glen Stampoultzis (glens at apache.org)
  */
-public class TestSSTDeserializer
-        extends TestCase
-{
-    private String _test_file_path;
-    private static final String _test_file_path_property = "HSSF.testdata.path";
+public final class TestSSTDeserializer extends TestCase {
 
-    public TestSSTDeserializer( String s )
-    {
-        super( s );
-    }
-
-    protected void setUp() throws Exception
-    {
-        _test_file_path = System.getProperty( _test_file_path_property );
-    }
 
     private byte[] joinArray(byte[] array1, byte[] array2) {
-      byte[] bigArray = new byte[array1.length+array2.length];
-      System.arraycopy(array1, 0, bigArray, 0, array1.length);
-      System.arraycopy(array2, 0, bigArray, array1.length, array2.length);
-      return bigArray;    
+        byte[] bigArray = new byte[array1.length + array2.length];
+        System.arraycopy(array1, 0, bigArray, 0, array1.length);
+        System.arraycopy(array2, 0, bigArray, array1.length, array2.length);
+        return bigArray;
+    }
+    
+    private static byte[] readSampleHexData(String sampleFileName, String sectionName) {
+        InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
+        try {
+            return HexRead.readData(is, sectionName);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
     }
 
     public void testSpanRichTextToPlainText()
             throws Exception
     {
-      byte[] header = HexRead.readData( _test_file_path + File.separator + "richtextdata.txt",
"header" );
-        byte[] continueBytes = HexRead.readData( _test_file_path + File.separator + "richtextdata.txt",
"continue1" );
+      byte[] header = readSampleHexData("richtextdata.txt", "header" );
+        byte[] continueBytes = readSampleHexData("richtextdata.txt", "continue1" );
       continueBytes = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continueBytes.length,
continueBytes);
       TestcaseRecordInputStream in = new TestcaseRecordInputStream((short)0, (short)header.length,
joinArray(header, continueBytes));
       
@@ -74,8 +69,8 @@
     public void testContinuationWithNoOverlap()
             throws Exception
     {
-        byte[] header = HexRead.readData( _test_file_path + File.separator + "evencontinuation.txt",
"header" );
-        byte[] continueBytes = HexRead.readData( _test_file_path + File.separator + "evencontinuation.txt",
"continue1" );
+        byte[] header = readSampleHexData("evencontinuation.txt", "header" );
+        byte[] continueBytes = readSampleHexData("evencontinuation.txt", "continue1" );
         continueBytes = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continueBytes.length,
continueBytes);
         TestcaseRecordInputStream in = new TestcaseRecordInputStream((short)0, (short)header.length,
joinArray(header, continueBytes));
 
@@ -93,10 +88,10 @@
     public void testStringAcross2Continuations()
             throws Exception
     {
-        byte[] header = HexRead.readData( _test_file_path + File.separator + "stringacross2continuations.txt",
"header" );
-        byte[] continue1 = HexRead.readData( _test_file_path + File.separator + "stringacross2continuations.txt",
"continue1" );
+        byte[] header = readSampleHexData("stringacross2continuations.txt", "header" );
+        byte[] continue1 = readSampleHexData("stringacross2continuations.txt", "continue1"
);
         continue1 = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continue1.length,
continue1);
-        byte[] continue2 = HexRead.readData( _test_file_path + File.separator + "stringacross2continuations.txt",
"continue2" );
+        byte[] continue2 = readSampleHexData("stringacross2continuations.txt", "continue2"
);
         continue2 = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continue2.length,
continue2);
         
         byte[] bytes = joinArray(header, continue1);
@@ -111,11 +106,9 @@
         assertEquals( "At a dinner partyAt a dinner party", strings.get( 1 ) + "" );
     }
 
-    public void testExtendedStrings()
-            throws Exception
-    {
-        byte[] header = HexRead.readData( _test_file_path + File.separator + "extendedtextstrings.txt",
"rich-header" );
-        byte[] continueBytes = HexRead.readData( _test_file_path + File.separator + "extendedtextstrings.txt",
"rich-continue1" );
+    public void testExtendedStrings() {
+        byte[] header = readSampleHexData("extendedtextstrings.txt", "rich-header" );
+        byte[] continueBytes = readSampleHexData("extendedtextstrings.txt", "rich-continue1"
);
         continueBytes = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continueBytes.length,
continueBytes);
         TestcaseRecordInputStream in = new TestcaseRecordInputStream((short)0, (short)header.length,
joinArray(header, continueBytes));
         
@@ -126,8 +119,8 @@
         assertEquals( "At a dinner party orAt At At ", strings.get( 0  ) + "" );
 
 
-        header = HexRead.readData( _test_file_path + File.separator + "extendedtextstrings.txt",
"norich-header" );
-        continueBytes = HexRead.readData( _test_file_path + File.separator + "extendedtextstrings.txt",
"norich-continue1" );
+        header = readSampleHexData("extendedtextstrings.txt", "norich-header" );
+        continueBytes = readSampleHexData("extendedtextstrings.txt", "norich-continue1" );
         continueBytes = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continueBytes.length,
continueBytes);
         in = new TestcaseRecordInputStream((short)0, (short)header.length, joinArray(header,
continueBytes));
         
@@ -136,7 +129,5 @@
         deserializer.manufactureStrings( 1, in);
 
         assertEquals( "At a dinner party orAt At At ", strings.get( 0 ) + "" );
-
     }
-
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java Mon Apr
 7 05:51:50 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,54 +14,33 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Iterator;
+
 import junit.framework.TestCase;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.util.HexRead;
 import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.LittleEndianConsts;
-import org.apache.poi.util.TempFile;
-
-import java.io.*;
-import java.util.Arrays;
-import java.util.Iterator;
 
 /**
  * @author Marc Johnson (mjohnson at apache dot org)
  * @author Glen Stampoultzis (glens at apache.org)
  */
 
-public class TestSSTRecord
-        extends TestCase
-{
-    private String _test_file_path;
-    private static final String _test_file_path_property = "HSSF.testdata.path";
-
-    /**
-     * Creates new TestSSTRecord
-     *
-     * @param name
-     */
-
-    public TestSSTRecord( String name )
-    {
-        super( name );
-        _test_file_path = System.getProperty( _test_file_path_property );
-    }
+public final class TestSSTRecord extends TestCase {
 
     /**
      * test processContinueRecord
-     *
-     * @exception IOException
      */
-
-    public void testProcessContinueRecord()
-            throws IOException
-    {
+    public void testProcessContinueRecord() {
 //jmh        byte[] testdata = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord"
);
 //jmh        byte[] input = new byte[testdata.length - 4];
 //jmh
@@ -182,9 +160,7 @@
      * @exception IOException
      */
 
-    public void testHugeStrings()
-            throws IOException
-    {
+    public void testHugeStrings() {
         SSTRecord record = new SSTRecord();
         byte[][] bstrings =
                 {
@@ -265,12 +241,8 @@
 
     /**
      * test SSTRecord boundary conditions
-     *
-     * @exception IOException
      */
-    public void testSSTRecordBug()
-            throws IOException
-    {
+    public void testSSTRecordBug() {
         // create an SSTRecord and write a certain pattern of strings
         // to it ... then serialize it and verify the content
         SSTRecord record = new SSTRecord();
@@ -350,38 +322,6 @@
     }
 
     /**
-     * test reader constructor
-     *
-     * @exception IOException
-     */
-
-    public void testReaderConstructor()
-            throws IOException
-    {
-/* JMH this test case data is crap because it does not contain a full record. Ie the last
string
-       is missing a record
-
-        byte[] testdata = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord"
);
-//        byte[] input = new byte[testdata.length - 4];
-
-        System.arraycopy( testdata, 4, input, 0, input.length );
-        SSTRecord record = new SSTRecord( new TestcaseRecordInputStream(LittleEndian.getShort(
testdata, 0 ),
-                LittleEndian.getShort( testdata, 2 ),
-                input) );
-
-        assertEquals( 1464, record.getNumStrings() );
-        assertEquals( 688, record.getNumUniqueStrings() );
-        assertEquals( 492, record.countStrings() );
-        assertEquals( 1, record.getDeserializer().getContinuationExpectedChars() );
-        assertEquals( "Consolidated B-24J Liberator The Dragon & His Tai",
-                record.getDeserializer().getUnfinishedString() );
-//        assertEquals( 52, record.getDeserializer().getTotalLength() );
-//        assertEquals( 3, record.getDeserializer().getStringDataOffset() );
-        assertTrue( !record.getDeserializer().isWideChar() );
- */
-    }
-
-    /**
      * test simple constructor
      */
 
@@ -413,9 +353,7 @@
      * @param ignored_args
      */
 
-    public static void main( String[] ignored_args )
-    {
-        System.out.println( "Testing hssf.record.SSTRecord functionality" );
+    public static void main( String[] ignored_args ) {
         junit.textui.TestRunner.run( TestSSTRecord.class );
     }
 
@@ -425,25 +363,16 @@
     public void testReadWriteDuplicatedRichText1()
             throws Exception
     {
-        File file = new File( _test_file_path + File.separator + "duprich1.xls" );
-        InputStream stream = new FileInputStream( file );
-        HSSFWorkbook wb = new HSSFWorkbook( stream );
-        stream.close();
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("duprich1.xls");
         HSSFSheet sheet = wb.getSheetAt( 1 );
         assertEquals( "01/05 (Wed)", sheet.getRow( 0 ).getCell( (short) 8 ).getStringCellValue()
);
         assertEquals( "01/05 (Wed)", sheet.getRow( 1 ).getCell( (short) 8 ).getStringCellValue()
);
 
-        file = TempFile.createTempFile( "testout", "xls" );
-        FileOutputStream outStream = new FileOutputStream( file );
-        wb.write( outStream );
-        outStream.close();
-        file.delete();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        wb.write( baos );
 
         // test the second file.
-        file = new File( _test_file_path + File.separator + "duprich2.xls" );
-        stream = new FileInputStream( file );
-        wb = new HSSFWorkbook( stream );
-        stream.close();
+        wb = HSSFTestDataSamples.openSampleWorkbook("duprich2.xls");
         sheet = wb.getSheetAt( 0 );
         int row = 0;
         assertEquals( "Testing", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue()
);
@@ -453,12 +382,6 @@
         assertEquals( "Testing", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue()
);
         assertEquals( "Testing", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue()
);
 
-//        file = new File("/tryme.xls");
-        file = TempFile.createTempFile( "testout", ".xls" );
-        outStream = new FileOutputStream( file );
-        wb.write( outStream );
-        outStream.close();
-        file.delete();
+        wb.write( baos );
     }
-
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java
Mon Apr  7 05:51:50 2008
@@ -14,39 +14,23 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record;
 
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
 import junit.framework.TestCase;
 
-import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+/**
+ * 
+ */
+public final class TestUnicodeNameRecord extends TestCase {
 
-public class TestUnicodeNameRecord extends TestCase {
-    private String _test_file_path;
-    private static final String _test_file_path_property = "HSSF.testdata.path";
-
-    public TestUnicodeNameRecord()
-    {
-        super();
-        _test_file_path = System.getProperty( _test_file_path_property ) +
-        	File.separator + "unicodeNameRecord.xls";
-    }
-
-	public void testReadBook() throws IOException {
-    	POIFSFileSystem fs = new POIFSFileSystem(
-    			new FileInputStream(_test_file_path)
-    	);
+	public void testReadBook() {
 
 		// This bit used to crash
-    	HSSFWorkbook book = new HSSFWorkbook(fs);
-    	HSSFSheet sheet = book.getSheetAt(0);
+		HSSFWorkbook book = HSSFTestDataSamples.openSampleWorkbook("unicodeNameRecord.xls");
+		book.getSheetAt(0);
 	}
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java
Mon Apr  7 05:51:50 2008
@@ -29,6 +29,7 @@
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.record.BlankRecord;
 import org.apache.poi.hssf.record.FormulaRecord;
 import org.apache.poi.hssf.record.Record;
@@ -250,22 +251,14 @@
      * 
      */
     public void testSpuriousSharedFormulaFlag() {
-        File dataDir = new File(System.getProperty("HSSF.testdata.path"));
-        File testFile = new File(dataDir, ABNORMAL_SHARED_FORMULA_FLAG_TEST_FILE);
         
-        long actualCRC = getFileCRC(testFile);
+        long actualCRC = getFileCRC(HSSFTestDataSamples.openSampleFileStream(ABNORMAL_SHARED_FORMULA_FLAG_TEST_FILE));
         long expectedCRC = 2277445406L;
         if(actualCRC != expectedCRC) {
             System.err.println("Expected crc " + expectedCRC  + " but got " + actualCRC);
             throw failUnexpectedTestFileChange();
         }
-        HSSFWorkbook wb;
-        try {
-            FileInputStream in = new FileInputStream(testFile);
-            wb = new HSSFWorkbook(in);
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook(ABNORMAL_SHARED_FORMULA_FLAG_TEST_FILE);
         
         HSSFSheet s = wb.getSheetAt(0); // Sheet1
         
@@ -311,11 +304,10 @@
     /**
      * gets a CRC checksum for the content of a file
      */
-    private static long getFileCRC(File f) {
+    private static long getFileCRC(InputStream is) {
         CRC32 crc = new CRC32();
         byte[] buf = new byte[2048];
         try {
-            InputStream is = new FileInputStream(f);
             while(true) {
                 int bytesRead = is.read(buf);
                 if(bytesRead < 1) {

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java
Mon Apr  7 05:51:50 2008
@@ -25,6 +25,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@@ -36,40 +37,27 @@
  * @author Daniel Noll (daniel at nuix dot com dot au)
  */
 public abstract class AbstractPtgTestCase extends TestCase {
-    /** Directory containing the test data. */
-    private static String dataDir = System.getProperty("HSSF.testdata.path");
 
     /**
      * Loads a workbook from the given filename in the test data dir.
      *
-     * @param filename the filename.
+     * @param sampleFileName the filename.
      * @return the loaded workbook.
-     * @throws IOException if an error occurs loading the workbook.
      */
-    protected static final HSSFWorkbook loadWorkbook(String filename)
-            throws IOException {
-        File file = new File(dataDir, filename);
-        InputStream stream = new BufferedInputStream(new FileInputStream(file));
-        // TODO - temp workaround to keep stdout quiet due to warning msg in POIFS 
-        // When that warning msg is disabled, remove this wrapper and the close() call, 
-        InputStream wrappedStream = POIFSFileSystem.createNonClosingInputStream(stream);
-        try {
-            return new HSSFWorkbook(wrappedStream);
-        } finally {
-            stream.close();
-        }
+    protected static final HSSFWorkbook loadWorkbook(String sampleFileName) {
+        return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
     }
 
     /**
      * Creates a new Workbook and adds one sheet with the specified name
      */
     protected static final Workbook createWorkbookWithSheet(String sheetName) {
-		
-		Workbook book = Workbook.createWorkbook();
-		// this creates sheet if it doesn't exist
-		book.checkExternSheet(0);
-		// TODO - this call alone does not create the sheet even though the javadoc says it does
-		book.setSheetName(0, sheetName); 
-		return book;
-	}
+        
+        Workbook book = Workbook.createWorkbook();
+        // this creates sheet if it doesn't exist
+        book.checkExternSheet(0);
+        // TODO - this call alone does not create the sheet even though the javadoc says
it does
+        book.setSheetName(0, sheetName); 
+        return book;
+    }
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java
Mon Apr  7 05:51:50 2008
@@ -17,11 +17,9 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import java.io.FileInputStream;
-import java.io.IOException;
-
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 /**
@@ -37,15 +35,7 @@
      * tests <tt>NameXPtg.toFormulaString(Workbook)</tt> and logic in Workbook
below that   
      */
     public void testReadFormulaContainingExternalFunction() {
-        String filePath = System.getProperty("HSSF.testdata.path")+ "/" 
-        + "externalFunctionExample.xls";
-        HSSFWorkbook wb;
-        try {
-            FileInputStream fin = new FileInputStream(filePath);
-            wb = new HSSFWorkbook( fin );
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls");
         
         String expectedFormula = "YEARFRAC(B1,C1)";
         HSSFSheet sht = wb.getSheetAt(0);

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java
Mon Apr  7 05:51:50 2008
@@ -17,9 +17,6 @@
 
 package org.apache.poi.hssf.record.formula.eval;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -27,6 +24,7 @@
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
 import org.apache.poi.hssf.usermodel.HSSFRow;
@@ -43,49 +41,13 @@
  */
 public final class TestFormulaBugs extends TestCase {
 
-	private static final String TEST_DATA_DIR_SYS_PROPERTY_NAME = "HSSF.testdata.path";
-
-	/**
-	 * Opens a sample file from the standard HSSF test data directory
-	 * 
-	 * @return an open <tt>InputStream</tt> for the specified sample file
-	 */
-	private static InputStream openSampleFileStream(String sampleFileName) {
-		// TODO - move this method somewhere common
-		String dataDirName = System
-				.getProperty(TEST_DATA_DIR_SYS_PROPERTY_NAME);
-		if (dataDirName == null) {
-			throw new RuntimeException("Must set system property '"
-					+ TEST_DATA_DIR_SYS_PROPERTY_NAME
-					+ "' before running tests");
-		}
-		File dataDir = new File(dataDirName);
-		if (!dataDir.exists()) {
-			throw new RuntimeException("Data dir '" + dataDirName
-					+ "' specified by system property '"
-					+ TEST_DATA_DIR_SYS_PROPERTY_NAME + "' does not exist");
-		}
-		File f = new File(dataDir, sampleFileName);
-		if (!f.exists()) {
-			throw new RuntimeException("Sample file '" + sampleFileName
-					+ "' not found in data dir '" + dataDirName + "'");
-		}
-		InputStream is;
-		try {
-			is = new FileInputStream(f);
-		} catch (FileNotFoundException e) {
-			throw new RuntimeException(e);
-		}
-		return is;
-	}
-
 	/**
 	 * Bug 27349 - VLOOKUP with reference to another sheet.<p/> This test was
 	 * added <em>long</em> after the relevant functionality was fixed.
 	 */
 	public void test27349() {
 		// 27349-vlookupAcrossSheets.xls is bugzilla/attachment.cgi?id=10622
-		InputStream is = openSampleFileStream("27349-vlookupAcrossSheets.xls");
+		InputStream is = HSSFTestDataSamples.openSampleFileStream("27349-vlookupAcrossSheets.xls");
 		HSSFWorkbook wb;
 		try {
 			// original bug may have thrown exception here, or output warning to

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java
Mon Apr  7 05:51:50 2008
@@ -17,13 +17,13 @@
 
 package org.apache.poi.hssf.record.formula.eval;
 
-import java.io.FileInputStream;
 import java.io.PrintStream;
 
 import junit.framework.Assert;
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.record.formula.functions.TestMathX;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.Cell;
@@ -155,9 +155,7 @@
 
 	protected void setUp() throws Exception {
 		if (workbook == null) {
-			String filePath = System.getProperty("HSSF.testdata.path")+ "/" + SS.FILENAME;
-			FileInputStream fin = new FileInputStream( filePath );
-			workbook = new HSSFWorkbook( fin );
+			workbook = HSSFTestDataSamples.openSampleWorkbook(SS.FILENAME);
 			sheet = workbook.getSheetAt( 0 );
 		  }
 		_functionFailureCount = 0;
@@ -178,14 +176,14 @@
 		String successMsg = "There were " 
 				+ _evaluationSuccessCount + " successful evaluation(s) and "
 				+ _functionSuccessCount + " function(s) without error";
- 		if(_functionFailureCount > 0) {
+		if(_functionFailureCount > 0) {
 			String msg = _functionFailureCount + " function(s) failed in "
 			+ _evaluationFailureCount + " evaluation(s).  " + successMsg;
 			throw new AssertionFailedError(msg);
 		}
- 		if(false) { // normally no output for successful tests
- 			System.out.println(getClass().getName() + ": " + successMsg);
- 		}
+		if(false) { // normally no output for successful tests
+			System.out.println(getClass().getName() + ": " + successMsg);
+		}
 	}
 
 	/**

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java
Mon Apr  7 05:51:50 2008
@@ -23,6 +23,7 @@
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.record.RecordFormatException;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -45,14 +46,7 @@
 
 	private static HSSFSheet getSheet() {
 		if (_sheet == null) {
-			String cwd = System.getProperty("HSSF.testdata.path");
-			HSSFWorkbook wb;
-			try {
-				InputStream is = new FileInputStream(new File(cwd, SAMPLE_SPREADSHEET_FILE_NAME));
-				wb = new HSSFWorkbook(is);
-			} catch (IOException e) {
-				throw new RuntimeException(e);
-			}
+			HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook(SAMPLE_SPREADSHEET_FILE_NAME);
 			_sheet = wb.getSheetAt(0);
 		}
 		return _sheet;

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestLookupFunctionsFromSpreadsheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestLookupFunctionsFromSpreadsheet.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestLookupFunctionsFromSpreadsheet.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestLookupFunctionsFromSpreadsheet.java
Mon Apr  7 05:51:50 2008
@@ -26,6 +26,7 @@
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.record.formula.eval.ErrorEval;
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
@@ -66,17 +67,17 @@
 		public final static String README_SHEET_NAME = "Read Me";
 		
 		
-	    /** Row (zero-based) in each sheet where the evaluation cases start.   */
+		/** Row (zero-based) in each sheet where the evaluation cases start.   */
 		public static final int START_TEST_CASES_ROW_INDEX = 4; // Row '5'
 		/**  Index of the column that contains the function names */
-	    public static final short COLUMN_INDEX_MARKER = 0; // Column 'A'
-	    public static final short COLUMN_INDEX_EVALUATION = 1; // Column 'B'
-	    public static final short COLUMN_INDEX_EXPECTED_RESULT = 2; // Column 'C'
-	    public static final short COLUMN_ROW_COMMENT = 3; // Column 'D'
+		public static final short COLUMN_INDEX_MARKER = 0; // Column 'A'
+		public static final short COLUMN_INDEX_EVALUATION = 1; // Column 'B'
+		public static final short COLUMN_INDEX_EXPECTED_RESULT = 2; // Column 'C'
+		public static final short COLUMN_ROW_COMMENT = 3; // Column 'D'
 	
-	    /** Used to indicate when there are no more test cases on the current sheet   */
+		/** Used to indicate when there are no more test cases on the current sheet   */
 		public static final String TEST_CASES_END_MARKER = "<end>";
-	    /** Used to indicate that the test on the current row should be ignored */
+		/** Used to indicate that the test on the current row should be ignored */
 		public static final String SKIP_CURRENT_TEST_CASE_MARKER = "<skip>";
 	
 	}
@@ -90,8 +91,8 @@
 
 
 
-    private static void confirmExpectedResult(String msg, HSSFCell expected, CellValue actual)
{
-        if (expected == null) {
+	private static void confirmExpectedResult(String msg, HSSFCell expected, CellValue actual)
{
+		if (expected == null) {
 			throw new AssertionFailedError(msg + " - Bad setup data expected value is null");
 		}
 		if(actual == null) {
@@ -108,21 +109,21 @@
 			throw wrongTypeError(msg, expected, actual);
 		}
 		
-        
+		
 		switch (expected.getCellType()) {
 			case HSSFCell.CELL_TYPE_BOOLEAN:
-			    assertEquals(msg, expected.getBooleanCellValue(), actual.getBooleanValue());
-			    break;
+				assertEquals(msg, expected.getBooleanCellValue(), actual.getBooleanValue());
+				break;
 			case HSSFCell.CELL_TYPE_FORMULA: // will never be used, since we will call method after
formula evaluation
-			    throw new AssertionFailedError("Cannot expect formula as result of formula evaluation:
" + msg);
+				throw new AssertionFailedError("Cannot expect formula as result of formula evaluation:
" + msg);
 			case HSSFCell.CELL_TYPE_NUMERIC:
-			    assertEquals(expected.getNumericCellValue(), actual.getNumberValue(), 0.0);
-			    break;
+				assertEquals(expected.getNumericCellValue(), actual.getNumberValue(), 0.0);
+				break;
 			case HSSFCell.CELL_TYPE_STRING:
-			    assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getRichTextStringValue().getString());
-			    break;
+				assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getRichTextStringValue().getString());
+				break;
 		}
-    }
+	}
 
 
 	private static AssertionFailedError wrongTypeError(String msgPrefix, HSSFCell expectedCell,
CellValue actualValue) {
@@ -178,55 +179,48 @@
 
 
 	protected void setUp() throws Exception {
-        _sheetFailureCount = 0;
-        _sheetSuccessCount = 0;
-        _evaluationFailureCount = 0;
-        _evaluationSuccessCount = 0;
-    }
-    
-    public void testFunctionsFromTestSpreadsheet() {
-    	String filePath = System.getProperty("HSSF.testdata.path")+ "/" + SS.FILENAME;
-        HSSFWorkbook workbook;
-		try {
-			FileInputStream fin = new FileInputStream( filePath );
-			workbook = new HSSFWorkbook( fin );
-		} catch (IOException e) {
-			throw new RuntimeException(e);
-		}
+		_sheetFailureCount = 0;
+		_sheetSuccessCount = 0;
+		_evaluationFailureCount = 0;
+		_evaluationSuccessCount = 0;
+	}
+	
+	public void testFunctionsFromTestSpreadsheet() {
+		HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook(SS.FILENAME);
    	
-    	confirmReadMeSheet(workbook);
-    	int nSheets = workbook.getNumberOfSheets();
-    	for(int i=1; i< nSheets; i++) {
-    		int sheetResult = processTestSheet(workbook, i, workbook.getSheetName(i));
-    		switch(sheetResult) {
-    			case Result.ALL_EVALUATIONS_SUCCEEDED: _sheetSuccessCount ++; break; 
-    			case Result.SOME_EVALUATIONS_FAILED: _sheetFailureCount ++; break; 
-    		}
-    	}
-        
-        // confirm results
-    	String successMsg = "There were " 
-    			+ _sheetSuccessCount + " successful sheets(s) and "
+		confirmReadMeSheet(workbook);
+		int nSheets = workbook.getNumberOfSheets();
+		for(int i=1; i< nSheets; i++) {
+			int sheetResult = processTestSheet(workbook, i, workbook.getSheetName(i));
+			switch(sheetResult) {
+				case Result.ALL_EVALUATIONS_SUCCEEDED: _sheetSuccessCount ++; break; 
+				case Result.SOME_EVALUATIONS_FAILED: _sheetFailureCount ++; break; 
+			}
+		}
+		
+		// confirm results
+		String successMsg = "There were " 
+				+ _sheetSuccessCount + " successful sheets(s) and "
 				+ _evaluationSuccessCount + " function(s) without error";
  		if(_sheetFailureCount > 0) {
 			String msg = _sheetFailureCount + " sheets(s) failed with "
 			+ _evaluationFailureCount + " evaluation(s).  " + successMsg;
-        	throw new AssertionFailedError(msg);
-        }
+			throw new AssertionFailedError(msg);
+		}
  		if(false) { // normally no output for successful tests
  			System.out.println(getClass().getName() + ": " + successMsg);
  		}
 	}
 
-    private int processTestSheet(HSSFWorkbook workbook, int sheetIndex, String sheetName)
{
+	private int processTestSheet(HSSFWorkbook workbook, int sheetIndex, String sheetName) {
 		HSSFSheet sheet = workbook.getSheetAt(sheetIndex);
 		HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, workbook);
 		int maxRows = sheet.getLastRowNum()+1;
-        int result = Result.NO_EVALUATIONS_FOUND; // so far
+		int result = Result.NO_EVALUATIONS_FOUND; // so far
 		
 		String currentGroupComment = null;
 		for(int rowIndex=SS.START_TEST_CASES_ROW_INDEX; rowIndex<maxRows; rowIndex++) {
-            HSSFRow r = sheet.getRow(rowIndex);
+			HSSFRow r = sheet.getRow(rowIndex);
 			String newMarkerValue = getMarkerColumnValue(r);
 			if(r == null) {
 				continue;
@@ -242,7 +236,7 @@
 			if(newMarkerValue != null) {
 				currentGroupComment = newMarkerValue;
 			}
-            HSSFCell c = r.getCell(SS.COLUMN_INDEX_EVALUATION);
+			HSSFCell c = r.getCell(SS.COLUMN_INDEX_EVALUATION);
 			if (c == null || c.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
 				continue;
 			}
@@ -303,11 +297,11 @@
 	}
 
 	/**
-     * Asserts that the 'read me' comment page exists, and has this class' name in one of
the 
-     * cells.  This back-link is to make it easy to find this class if a reader encounters
the 
-     * spreadsheet first.
-     */
-    private void confirmReadMeSheet(HSSFWorkbook workbook) {
+	 * Asserts that the 'read me' comment page exists, and has this class' name in one of the

+	 * cells.  This back-link is to make it easy to find this class if a reader encounters the

+	 * spreadsheet first.
+	 */
+	private void confirmReadMeSheet(HSSFWorkbook workbook) {
 		String firstSheetName = workbook.getSheetName(0);
 		if(!firstSheetName.equalsIgnoreCase(SS.README_SHEET_NAME)) {
 			throw new RuntimeException("First sheet's name was '" + firstSheetName + "' but expected
'" + SS.README_SHEET_NAME + "'");
@@ -319,9 +313,9 @@
 	}
 
 
-    /**
-     * Useful to keep output concise when expecting many failures to be reported by this
test case
-     */
+	/**
+	 * Useful to keep output concise when expecting many failures to be reported by this test
case
+	 */
 	private static void printShortStackTrace(PrintStream ps, Throwable e) {
 		StackTraceElement[] stes = e.getStackTrace();
 		
@@ -363,7 +357,7 @@
 	
 	/**
 	 * @return <code>null</code> if cell is missing, empty or blank
-     */
+	 */
 	private static String getCellTextValue(HSSFRow r, int colIndex, String columnName) {
 		if(r == null) {
 			return null;

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java Mon Apr
 7 05:51:50 2008
@@ -14,42 +14,35 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
+
 package org.apache.poi.hssf.usermodel;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.util.Iterator;
 import java.util.List;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.record.FormulaRecord;
 import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
 import org.apache.poi.ss.usermodel.FormulaEvaluator.CellValue;
 import org.apache.poi.hssf.util.CellReference;
 
+/**
+ * 
+ */
 public final class TestBug42464 extends TestCase {
-	String dirname;
-
-	protected void setUp() throws Exception {
-		super.setUp();
-		dirname = System.getProperty("HSSF.testdata.path");
-	}
 
 	public void testOKFile() throws Exception {
-		HSSFWorkbook wb = new HSSFWorkbook(
-				new FileInputStream(new File(dirname,"42464-ExpPtg-ok.xls"))
-		);
+		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("42464-ExpPtg-ok.xls");
 		process(wb);
 	}
 	public void testExpSharedBadFile() throws Exception {
-		HSSFWorkbook wb = new HSSFWorkbook(
-				new FileInputStream(new File(dirname,"42464-ExpPtg-bad.xls"))
-		);
+		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("42464-ExpPtg-bad.xls");
 		process(wb);
 	}
 	
-	protected void process(HSSFWorkbook wb) {
+	private static void process(HSSFWorkbook wb) {
 		for(int i=0; i<wb.getNumberOfSheets(); i++) {
 			HSSFSheet s = wb.getSheetAt(i);
 			HSSFFormulaEvaluator eval =
@@ -64,7 +57,7 @@
 		}
 	}
 	
-	protected void process(HSSFRow row, HSSFFormulaEvaluator eval) {
+	private static void process(HSSFRow row, HSSFFormulaEvaluator eval) {
 		Iterator it = row.cellIterator();
 		while(it.hasNext()) {
 			HSSFCell cell = (HSSFCell)it.next();



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message