poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject svn commit: r618325 [2/2] - in /poi/branches/ooxml: ./ src/documentation/content/xdocs/ src/java/org/apache/poi/hssf/dev/ src/java/org/apache/poi/hssf/eventusermodel/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/ src/java/org...
Date Mon, 04 Feb 2008 16:55:47 GMT
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=618325&r1=618324&r2=618325&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 Feb  4 08:55:43 2008
@@ -26,6 +26,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
 /**
@@ -34,7 +35,7 @@
  *
  * @author Daniel Noll (daniel at nuix dot com dot au)
  */
-public class AbstractPtgTestCase extends TestCase
+public abstract class AbstractPtgTestCase extends TestCase
 {
     /** Directory containing the test data. */
     private static String dataDir = System.getProperty("HSSF.testdata.path");
@@ -46,7 +47,7 @@
      * @return the loaded workbook.
      * @throws IOException if an error occurs loading the workbook.
      */
-    protected static HSSFWorkbook loadWorkbook(String filename)
+    protected static final HSSFWorkbook loadWorkbook(String filename)
             throws IOException {
         File file = new File(dataDir, filename);
         InputStream stream = new BufferedInputStream(new FileInputStream(file));
@@ -59,4 +60,18 @@
             stream.close();
         }
     }
+    
+    /**
+     * 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;
+	}
+    
 }

Propchange: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java
            ('svn:executable' removed)

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=618325&r1=618324&r2=618325&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Mon Feb 
4 08:55:43 2008
@@ -1008,9 +1008,45 @@
 
         wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
         assertTrue("No Exceptions while reading file", true);
-
     }
 
+	/**
+	 * Bug 42618: RecordFormatException reading a file containing
+	 * 	=CHOOSE(2,A2,A3,A4)
+	 * TODO - support getCellFormula too!
+	 */
+    public void test42618() throws Exception {
+        FileInputStream in = new FileInputStream(new File(cwd, "SimpleWithChoose.xls"));
+        HSSFWorkbook wb = new HSSFWorkbook(in);
+        in.close();
+
+        assertTrue("No Exceptions while reading file", true);
+
+        //serialize and read again
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        wb.write(out);
+        out.close();
+
+        wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+        assertTrue("No Exceptions while reading file", true);
+        
+        // Check we detect the string properly too
+        HSSFSheet s = wb.getSheetAt(0);
+        
+        // Textual value
+        HSSFRow r1 = s.getRow(0);
+        HSSFCell c1 = r1.getCell((short)1);
+        assertEquals("=CHOOSE(2,A2,A3,A4)", c1.getRichStringCellValue().toString());
+        
+        // Formula Value
+        HSSFRow r2 = s.getRow(1);
+        HSSFCell c2 = r2.getCell((short)1);
+        assertEquals(25, (int)c2.getNumericCellValue());
+        
+        // This will blow up with a 
+        //  "EmptyStackException"
+        //assertEquals("=CHOOSE(2,A2,A3,A4)", c2.getCellFormula());
+    }
 }
 
 

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java?rev=618325&r1=618324&r2=618325&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java Mon Feb
 4 08:55:43 2008
@@ -19,25 +19,20 @@
 
 package org.apache.poi.hssf.usermodel;
 
-import junit.framework.TestCase;
-
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.hssf.model.Sheet;
-import org.apache.poi.hssf.record.Record;
-import org.apache.poi.hssf.record.BOFRecord;
-import org.apache.poi.hssf.record.EOFRecord;
-import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.util.HSSFColor;
-import org.apache.poi.util.TempFile;
-
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
-
-import java.util.List;
-import java.util.Iterator;
 import java.util.Date;
 import java.util.GregorianCalendar;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.model.Sheet;
+import org.apache.poi.hssf.record.HyperlinkRecord;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.util.TempFile;
 
 /**
  * Tests various functionity having to do with HSSFCell.  For instance support for
@@ -308,7 +303,54 @@
             assertTrue("Bottom Border", (cs.getBorderBottom() == (short)1));
             
             in.close();
-    }    
+    }
+
+    /**
+     * Test reading hyperlinks
+     */
+    public void testWithHyperlink() throws Exception {
+        String dir = System.getProperty("HSSF.testdata.path");
+        File f = new File(dir, "WithHyperlink.xls");
+    	HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(f));
+
+        HSSFSheet sheet = wb.getSheetAt(0);
+        HSSFCell cell = sheet.getRow(4).getCell((short)0);
+        HSSFHyperlink link = cell.getHyperlink();
+        assertNotNull(link);
+
+        assertEquals("Foo", link.getLabel());
+        assertEquals("http://poi.apache.org/", link.getAddress());
+        assertEquals(4, link.getRow());
+        assertEquals(0, link.getColumn());
+    }
+    
+    /**
+     * Test reading hyperlinks
+     */
+    public void testWithTwoHyperlinks() throws Exception {
+        String dir = System.getProperty("HSSF.testdata.path");
+        File f = new File(dir, "WithTwoHyperLinks.xls");
+    	HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(f));
+    	
+        HSSFSheet sheet = wb.getSheetAt(0);
+
+        HSSFCell cell1 = sheet.getRow(4).getCell((short)0);
+        HSSFHyperlink link1 = cell1.getHyperlink();
+        assertNotNull(link1);
+        assertEquals("Foo", link1.getLabel());
+        assertEquals("http://poi.apache.org/", link1.getAddress());
+        assertEquals(4, link1.getRow());
+        assertEquals(0, link1.getColumn());
+
+        HSSFCell cell2 = sheet.getRow(8).getCell((short)1);
+        HSSFHyperlink link2 = cell2.getHyperlink();
+        assertNotNull(link2);
+        assertEquals("Bar", link2.getLabel());
+        assertEquals("http://poi.apache.org/", link2.getAddress());
+        assertEquals(8, link2.getRow());
+        assertEquals(1, link2.getColumn());
+
+    }
     
     /*tests the toString() method of HSSFCell*/
     public void testToString() throws Exception {

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java?rev=618325&r1=618324&r2=618325&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java Mon
Feb  4 08:55:43 2008
@@ -351,7 +351,7 @@
 	     String retrievedPrintArea = workbook.getPrintArea(0);
 	    
 	 	 assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);        
-	     assertEquals(reference, retrievedPrintArea);
+	     assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
 	     
 	 }
 
@@ -370,7 +370,7 @@
 		 String retrievedPrintArea = workbook.getPrintArea(0);
 	    
 		 assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);        
-		 assertEquals(sheetName+"!"+reference, retrievedPrintArea);
+		 assertEquals("'" + sheetName + "'!" + reference, retrievedPrintArea);
 	     
 	 }
 
@@ -437,7 +437,7 @@
 	     
 	 	String retrievedPrintArea = workbook.getPrintArea(0);       
 	 	assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);        
-	 	assertEquals("References Match", reference, retrievedPrintArea);
+	 	assertEquals("References Match", "'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
          
 	}
 
@@ -449,9 +449,9 @@
 	{
 	    HSSFWorkbook workbook = new HSSFWorkbook();        
 	    
-	    HSSFSheet sheet = workbook.createSheet("Sheet 1");
-	    sheet = workbook.createSheet("Sheet 2");
-	    sheet = workbook.createSheet("Sheet 3");
+	    HSSFSheet sheet = workbook.createSheet("Sheet1");
+	    sheet = workbook.createSheet("Sheet2");
+	    sheet = workbook.createSheet("Sheet3");
 	    
 	    String sheetName = workbook.getSheetName(0);
 		String reference = null;
@@ -508,9 +508,30 @@
 		String retrievedPrintArea = workbook.getPrintArea(0);
 	    
 		assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);        
-		assertEquals(reference, retrievedPrintArea);    	
+		assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);    	
     }
-     
+
+    
+    /**
+     * Tests the parsing of union area expressions, and re-display in the presence of sheet
names
+     * with special characters.
+     */
+    public void testPrintAreaUnion(){
+		HSSFWorkbook workbook = new HSSFWorkbook();        
+		HSSFSheet sheet = workbook.createSheet("Test Print Area");                
+		String sheetName = workbook.getSheetName(0);
+		
+ 
+		String reference =       sheetName +  "!$A$1:$B$1, " + sheetName + "!$D$1:$F$2";
+		String expResult = "'" + sheetName + "'!$A$1:$B$1,'" + sheetName + "'!$D$1:$F$2";
+		workbook.setPrintArea(0, reference);
+	             
+		String retrievedPrintArea = workbook.getPrintArea(0);
+	    
+		assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);        
+		assertEquals(expResult, retrievedPrintArea);    	
+    }
+    
     /**
      * Verifies an existing print area is deleted
      *



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


Mime
View raw message