poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r615859 - in /poi/trunk/src: java/org/apache/poi/hssf/record/formula/ testcases/org/apache/poi/hssf/data/ testcases/org/apache/poi/hssf/record/ testcases/org/apache/poi/hssf/usermodel/
Date Mon, 28 Jan 2008 12:18:17 GMT
Author: nick
Date: Mon Jan 28 04:18:12 2008
New Revision: 615859

URL: http://svn.apache.org/viewvc?rev=615859&view=rev
Log:
Mostly fix bug 42618 (really this time...) - can now open the file properly, but getCellFormula()
is still playing up (bug #44306 opened for this)

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/ConcatPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/RangePtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/UnknownPtg.java
    poi/trunk/src/testcases/org/apache/poi/hssf/data/TestDataValidation.xls
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/ConcatPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/ConcatPtg.java?rev=615859&r1=615858&r2=615859&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/ConcatPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/ConcatPtg.java Mon Jan 28 04:18:12
2008
@@ -34,11 +34,10 @@
     public final static byte sid  = 0x08;
     
     private final static String CONCAT = "&";
-
+    
     public ConcatPtg(RecordInputStream in)
     {
-
-        // doesn't need anything
+    	// No contents
     }
     
     public ConcatPtg() {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java?rev=615859&r1=615858&r2=615859&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java Mon Jan 28 04:18:12 2008
@@ -137,8 +137,8 @@
                  break;
         	  
              case DividePtg.sid :               // 0x06
-        	                  retval = new DividePtg(in);
-        	                  break;
+        	      retval = new DividePtg(in);
+        	      break;
         	  
              case PowerPtg.sid :                // 0x07
                  retval = new PowerPtg(in);
@@ -208,6 +208,7 @@
                 break;
  
              case AttrPtg.sid :                 // 0x19
+             case 0x1a :
                  retval = new AttrPtg(in);
         	                  break;
         	  
@@ -224,8 +225,8 @@
         	                  break;
  
              case NumberPtg.sid :               // 0x1f
-        	                 retval = new NumberPtg(in);
-        	                 break;
+        	      retval = new NumberPtg(in);
+        	      break;
         	  
              case ArrayPtg.sid :                // 0x20
              	retval = new ArrayPtg(in);
@@ -350,9 +351,12 @@
              case DeletedArea3DPtg.sid + 0x40 : // 0x7d
                  retval = new DeletedArea3DPtg(in);
                  break;
-
+                 
+             case 0x00:
+            	 retval = new UnknownPtg();
+            	 break;
+                 
             default :
-
                  //retval = new UnknownPtg();
                  throw new java.lang.UnsupportedOperationException(" Unknown Ptg in Formula:
0x"+
                         Integer.toHexString(( int ) id) + " (" + ( int ) id + ")");

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/RangePtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/RangePtg.java?rev=615859&r1=615858&r2=615859&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/RangePtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/RangePtg.java Mon Jan 28 04:18:12
2008
@@ -25,22 +25,22 @@
  */
 public class RangePtg extends OperationPtg
 {
+    public final static int  SIZE = 1;
     public final static byte sid  = 0x11;
 
-
     public RangePtg()
     {
     }
 
     public RangePtg(RecordInputStream in)
     {
-        // doesn't need anything
+    	// No contents
     }
 
 
     public int getSize()
     {
-        return 1;
+        return SIZE;
     }
 
     public void writeBytes( byte[] array, int offset )

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/UnknownPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/UnknownPtg.java?rev=615859&r1=615858&r2=615859&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/UnknownPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/UnknownPtg.java Mon Jan 28 04:18:12
2008
@@ -28,7 +28,7 @@
 public class UnknownPtg
     extends Ptg
 {
-    private short size;
+    private short size = 1;
 
     /** Creates new UnknownPtg */
 

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/data/TestDataValidation.xls
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/data/TestDataValidation.xls?rev=615859&r1=615858&r2=615859&view=diff
==============================================================================
Binary files - no diff available.

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java?rev=615859&r1=615858&r2=615859&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java Mon Jan 28 04:18:12
2008
@@ -21,6 +21,16 @@
 package org.apache.poi.hssf.record;
 
 
+import java.io.ByteArrayInputStream;
+
+import org.apache.poi.hssf.record.formula.AttrPtg;
+import org.apache.poi.hssf.record.formula.ConcatPtg;
+import org.apache.poi.hssf.record.formula.FuncVarPtg;
+import org.apache.poi.hssf.record.formula.IntPtg;
+import org.apache.poi.hssf.record.formula.RangePtg;
+import org.apache.poi.hssf.record.formula.ReferencePtg;
+import org.apache.poi.hssf.record.formula.UnknownPtg;
+
 import junit.framework.TestCase;
 
 /**
@@ -106,6 +116,52 @@
 		byte[] output = record.serialize();
 		assertEquals("Output size", 31, output.length); //includes sid+recordlength
     	assertEquals("Offset 22", 1, output[26]);
+    }
+    
+    public void testWithConcat()  throws Exception {
+    	// =CHOOSE(2,A2,A3,A4)
+    	byte[] data = new byte[] {
+    			6, 0, 68, 0,
+    			1, 0, 1, 0, 15, 0, 0, 0, 0, 0, 0, 0, 57,
+				64, 0, 0, 12, 0, 12, -4, 46, 0, 
+				30, 2, 0,    // Int - 2
+				25, 4, 3, 0, // Attr
+				8, 0,        // Concat 
+				17, 0,       // Range 
+				26, 0, 35, 0, // Bit like an attr
+				36, 1, 0, 0, -64, // Ref - A2
+				25, 8, 21, 0, // Attr
+				36, 2, 0, 0, -64, // Ref - A3
+				25,	8, 12, 0, // Attr
+				36, 3, 0, 0, -64, // Ref - A4
+				25, 8, 3, 0,  // Attr 
+				66, 4, 100, 0 // CHOOSE
+    	};
+    	RecordInputStream inp = new RecordInputStream(
+    			new ByteArrayInputStream(data)
+    	);
+    	inp.nextRecord();
+    	
+    	FormulaRecord fr = new FormulaRecord(inp);
+    	
+    	assertEquals(14, fr.getNumberOfExpressionTokens());
+    	assertEquals(IntPtg.class,       fr.getParsedExpression().get(0).getClass());
+    	assertEquals(AttrPtg.class,      fr.getParsedExpression().get(1).getClass());
+    	assertEquals(ConcatPtg.class,    fr.getParsedExpression().get(2).getClass());
+    	assertEquals(UnknownPtg.class,   fr.getParsedExpression().get(3).getClass());
+    	assertEquals(RangePtg.class,     fr.getParsedExpression().get(4).getClass());
+    	assertEquals(UnknownPtg.class,   fr.getParsedExpression().get(5).getClass());
+    	assertEquals(AttrPtg.class,      fr.getParsedExpression().get(6).getClass());
+    	assertEquals(ReferencePtg.class, fr.getParsedExpression().get(7).getClass());
+    	assertEquals(AttrPtg.class,      fr.getParsedExpression().get(8).getClass());
+    	assertEquals(ReferencePtg.class, fr.getParsedExpression().get(9).getClass());
+    	assertEquals(AttrPtg.class,      fr.getParsedExpression().get(10).getClass());
+    	assertEquals(ReferencePtg.class, fr.getParsedExpression().get(11).getClass());
+    	assertEquals(AttrPtg.class,      fr.getParsedExpression().get(12).getClass());
+    	assertEquals(FuncVarPtg.class,   fr.getParsedExpression().get(13).getClass());
+    	
+    	FuncVarPtg choose = (FuncVarPtg)fr.getParsedExpression().get(13);
+    	assertEquals("CHOOSE", choose.getName());
     }
     
     

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=615859&r1=615858&r2=615859&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Mon Jan 28 04:18:12
2008
@@ -1013,11 +1013,9 @@
 	/**
 	 * Bug 42618: RecordFormatException reading a file containing
 	 * 	=CHOOSE(2,A2,A3,A4)
+	 * TODO - support getCellFormula too!
 	 */
     public void test42618() throws Exception {
-        //Comment the test until we are sure it passes.
-        // Yegor, January 25, 2008
-        /*
         FileInputStream in = new FileInputStream(new File(cwd, "SimpleWithChoose.xls"));
         HSSFWorkbook wb = new HSSFWorkbook(in);
         in.close();
@@ -1031,7 +1029,23 @@
 
         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());
     }
 }
 



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


Mime
View raw message