You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2008/01/04 15:19:19 UTC

svn commit: r608846 [2/2] - in /poi/tags/REL_3_0_2_BETA2: ./ src/documentation/content/xdocs/ src/documentation/content/xdocs/hslf/ src/documentation/content/xdocs/hssf/ src/java/org/apache/poi/hssf/record/ src/java/org/apache/poi/hssf/usermodel/ src/j...

Modified: poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Substitute.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Substitute.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Substitute.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Substitute.java Fri Jan  4 06:19:14 2008
@@ -20,6 +20,98 @@
  */
 package org.apache.poi.hssf.record.formula.functions;
 
-public class Substitute extends NotImplementedFunction {
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.StringEval;
+import org.apache.poi.hssf.record.formula.eval.StringValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
 
+/**
+ * An implementation of the SUBSTITUTE function:
+ * Substitutes text in a text string with new text, some number of times.
+ * @author Manda Wilson < wilson at c bio dot msk cc dot org >
+ */
+public class Substitute extends TextFunction {
+	private static final int REPLACE_ALL = -1;
+	
+	/**
+	 *Substitutes text in a text string with new text, some number of times.
+	 * 
+	 * @see org.apache.poi.hssf.record.formula.eval.Eval
+	 */
+    public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {		
+    	Eval retval = null;
+        String oldStr = null;
+        String searchStr = null;
+        String newStr = null;
+        int numToReplace = REPLACE_ALL;
+        
+        switch (operands.length) {
+	        default:
+	            retval = ErrorEval.VALUE_INVALID;
+	        case 4:
+	        	ValueEval fourthveval = singleOperandEvaluate(operands[3], srcCellRow, srcCellCol);
+	        	if (fourthveval instanceof NumericValueEval) {
+	        		NumericValueEval numToReplaceEval = (NumericValueEval) fourthveval;
+	        		// NOTE: it is safe to cast to int here
+	                // because in Excel =SUBSTITUTE("teststr","t","T",1.9) 
+	                // returns Teststr 
+	                // so 1.9 must be truncated to 1
+		        	numToReplace = (int) numToReplaceEval.getNumberValue();
+	        	} else {
+	        		retval = ErrorEval.VALUE_INVALID;
+	        	}
+	        case 3:	
+	        	// first operand is text string containing characters to replace
+	            // second operand is text to find
+	            // third operand is replacement text
+	            ValueEval firstveval = singleOperandEvaluate(operands[0], srcCellRow, srcCellCol);
+	            ValueEval secondveval = singleOperandEvaluate(operands[1], srcCellRow, srcCellCol);
+	            ValueEval thirdveval = singleOperandEvaluate(operands[2], srcCellRow, srcCellCol);
+	            if (firstveval instanceof StringValueEval
+	            	&& secondveval instanceof StringValueEval
+	            	&& thirdveval instanceof StringValueEval) {
+	            	
+	                StringValueEval oldStrEval = (StringValueEval) firstveval;
+	                oldStr = oldStrEval.getStringValue();
+	                
+	                StringValueEval searchStrEval = (StringValueEval) secondveval;
+	               	searchStr = searchStrEval.getStringValue();
+	                
+	               	StringValueEval newStrEval = (StringValueEval) thirdveval;
+	               	newStr = newStrEval.getStringValue();
+	            } else {
+	            	retval = ErrorEval.VALUE_INVALID;
+	            }
+	    }
+	        
+        if (retval == null) {
+			if (numToReplace != REPLACE_ALL && numToReplace < 1) {
+				retval = ErrorEval.VALUE_INVALID;
+			} else if (searchStr.length() == 0) {
+				retval = new StringEval(oldStr);
+			} else {
+				StringBuffer strBuff = new StringBuffer();
+				int startIndex = 0;
+				int nextMatch = -1;
+				for (int leftToReplace = numToReplace; 
+					(leftToReplace > 0 || numToReplace == REPLACE_ALL) 
+						&& (nextMatch = oldStr.indexOf(searchStr, startIndex)) != -1;
+					leftToReplace--) {
+					// store everything from end of last match to start of this match
+					strBuff.append(oldStr.substring(startIndex, nextMatch));
+					strBuff.append(newStr);
+					startIndex = nextMatch + searchStr.length();
+				}
+				// store everything from end of last match to end of string
+				if (startIndex < oldStr.length()) {
+					strBuff.append(oldStr.substring(startIndex));
+				}
+				retval = new StringEval(strBuff.toString());
+			}
+        } 
+		return retval;
+    }
+    
 }

Modified: poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Trim.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Trim.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Trim.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Trim.java Fri Jan  4 06:19:14 2008
@@ -14,12 +14,62 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-/*
- * Created on May 15, 2005
- *
- */
 package org.apache.poi.hssf.record.formula.functions;
 
-public class Trim extends NotImplementedFunction {
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.StringEval;
+import org.apache.poi.hssf.record.formula.eval.StringValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
+/**
+ * An implementation of the TRIM function:
+ * Removes leading and trailing spaces from value if evaluated operand
+ *  value is string.
+ * @author Manda Wilson &lt; wilson at c bio dot msk cc dot org &gt;
+ */
+public class Trim extends TextFunction {
 
+	/**
+	 * Removes leading and trailing spaces from value if evaluated 
+	 *  operand value is string.
+	 * Returns StringEval only if evaluated operand is of type string 
+	 *  (and is not blank or null) or number. If evaluated operand is 
+	 *  of type string and is blank or null, or if evaluated operand is 
+	 *  of type blank, returns BlankEval.  Otherwise returns ErrorEval.
+	 * 
+	 * @see org.apache.poi.hssf.record.formula.eval.Eval
+	 */
+    public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+    	Eval retval = ErrorEval.VALUE_INVALID;
+        String str = null;
+        
+        switch (operands.length) {
+	        default:
+	            break;
+	        case 1:
+	            ValueEval veval = singleOperandEvaluate(operands[0], srcCellRow, srcCellCol);
+	            if (veval instanceof StringValueEval) {
+	                StringValueEval sve = (StringValueEval) veval;
+	                str = sve.getStringValue();
+	                if (str == null || str.trim().equals("")) {
+	                	return BlankEval.INSTANCE;
+	                }
+	            }
+	            else if (veval instanceof NumberEval) {
+	                NumberEval neval = (NumberEval) veval;
+	                str = neval.getStringValue();
+	            } 
+	            else if (veval instanceof BlankEval) {
+	            	return BlankEval.INSTANCE;
+	            }
+	    }
+	        
+        if (str != null) {
+            retval = new StringEval(str.trim());
+        } 
+        return retval;
+    }
 }

Modified: poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Year.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Year.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Year.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Year.java Fri Jan  4 06:19:14 2008
@@ -51,7 +51,7 @@
             if (ve instanceof NumericValueEval) {
                 NumericValueEval ne = (NumericValueEval) ve;
                 if (HSSFDateUtil.isValidExcelDate(ne.getNumberValue())) {
-                    java.util.Date d = HSSFDateUtil.getJavaDate(ne.getNumberValue());
+                    java.util.Date d = HSSFDateUtil.getJavaDate(ne.getNumberValue(), false); // XXX fix 1900/1904 problem
                     retval = new NumberEval(d.getYear()+1900);
                 } else {
                     retval = ErrorEval.NUM_ERROR;

Modified: poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java Fri Jan  4 06:19:14 2008
@@ -19,6 +19,8 @@
 package org.apache.poi.hwpf.model;
 
 import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
 
 import org.apache.poi.hwpf.model.io.*;
 
@@ -37,6 +39,7 @@
 {
   private static final int LIST_DATA_SIZE = 28;
   private static final int LIST_FORMAT_OVERRIDE_SIZE = 16;
+  private static POILogger log = POILogFactory.getLogger(ListTables.class);
 
   HashMap _listMap = new HashMap();
   ArrayList _overrideList = new ArrayList();
@@ -189,8 +192,13 @@
   public ListLevel getLevel(int listID, int level)
   {
     ListData lst = (ListData)_listMap.get(new Integer(listID));
-    ListLevel lvl = lst.getLevels()[level];
-    return lvl;
+    if(level < lst.numLevels()) {
+    	ListLevel lvl = lst.getLevels()[level];
+    	return lvl;
+    } else {
+    	log.log(POILogger.WARN, "Requested level " + level + " which was greater than the maximum defined (" + lst.numLevels() + ")"); 
+    	return null;
+    }
   }
 
   public ListData getListData(int listID)

Modified: poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java Fri Jan  4 06:19:14 2008
@@ -148,8 +148,10 @@
 
         for (int x = 0; x < itcMac; x++)
         {
-          if(hasTCs) rgtc[x] = TableCellDescriptor.convertBytesToTC(grpprl,
-              offset + (1 + ( (itcMac + 1) * 2) + (x * 20)));
+          // Sometimes, the grpprl does not contain data at every offset. I have no idea why this happens.
+          if(hasTCs && offset + (1 + ( (itcMac + 1) * 2) + (x * 20)) < grpprl.length)
+            rgtc[x] = TableCellDescriptor.convertBytesToTC(grpprl,
+               offset + (1 + ( (itcMac + 1) * 2) + (x * 20)));
           else
             rgtc[x] = new TableCellDescriptor();
         }

Modified: poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ListEntry.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ListEntry.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ListEntry.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ListEntry.java Fri Jan  4 06:19:14 2008
@@ -23,21 +23,28 @@
 import org.apache.poi.hwpf.model.ListLevel;
 import org.apache.poi.hwpf.model.ListTables;
 import org.apache.poi.hwpf.model.PAPX;
-
-import org.apache.poi.hwpf.sprm.SprmBuffer;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
 
 public class ListEntry
   extends Paragraph
 {
-  ListLevel _level;
-  ListFormatOverrideLevel _overrideLevel;
+	private static POILogger log = POILogFactory.getLogger(ListEntry.class);
+	
+	ListLevel _level;
+	ListFormatOverrideLevel _overrideLevel;
 
   ListEntry(PAPX papx, Range parent, ListTables tables)
   {
     super(papx, parent);
-    ListFormatOverride override = tables.getOverride(_props.getIlfo());
-    _overrideLevel = override.getOverrideLevel(_props.getIlvl());
-    _level = tables.getLevel(override.getLsid(), _props.getIlvl());
+    
+    if(tables != null) {
+	    ListFormatOverride override = tables.getOverride(_props.getIlfo());
+	    _overrideLevel = override.getOverrideLevel(_props.getIlvl());
+	    _level = tables.getLevel(override.getLsid(), _props.getIlvl());
+    } else {
+    	log.log(POILogger.WARN, "No ListTables found for ListEntry - document probably partly corrupt, and you may experience problems");
+    }
   }
 
   public int type()

Modified: poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java Fri Jan  4 06:19:14 2008
@@ -25,6 +25,7 @@
 import java.io.*;
 import java.util.HashSet;
 import java.util.HashMap;
+import java.util.ArrayList;
 import java.awt.*;
 
 /**
@@ -298,4 +299,35 @@
 
     }
 
+    /**
+     * Bug 38256:  RuntimeException: Couldn't instantiate the class for type with id 0.
+     * ( also fixed followup: getTextRuns() returns no text )
+     */
+    public void test43781 () throws Exception {
+        FileInputStream is = new FileInputStream(new File(cwd, "43781.ppt"));
+        SlideShow ppt = new SlideShow(is);
+        is.close();
+
+        assertTrue("No Exceptions while reading file", true);
+
+        Slide slide = ppt.getSlides()[0];
+        TextRun[] tr1 = slide.getTextRuns();
+
+        ArrayList lst = new ArrayList();
+        Shape[] shape = slide.getShapes();
+        for (int i = 0; i < shape.length; i++) {
+            if( shape[i] instanceof TextBox){
+                TextRun textRun = ((TextBox)shape[i]).getTextRun();
+                if(textRun != null) lst.add(textRun);
+            }
+
+        }
+        TextRun[] tr2 = new TextRun[lst.size()];
+        lst.toArray(tr2);
+
+        assertEquals(tr1.length, tr2.length);
+        for (int i = 0; i < tr1.length; i++) {
+            assertEquals(tr1[i].getText(), tr2[i].getText());
+        }
+    }
 }

Modified: poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java Fri Jan  4 06:19:14 2008
@@ -84,6 +84,21 @@
 	}
 	
 	/**
+	 * Test to see if we can read the FROM Chunk.
+	 * @throws ChunkNotFoundException 
+	 * 
+	 */
+	public void testReadDisplayFrom() throws ChunkNotFoundException {
+		try {
+			mapiMessage.getDisplayFrom();		
+		} catch(ChunkNotFoundException exp) {
+			return;
+		}
+		
+		TestCase.fail("Should have thrown a ChunkNotFoundException but didn't");
+	}
+	
+	/**
 	 * Test to see if we can read the CC Chunk.
 	 * @throws ChunkNotFoundException 
 	 * 

Modified: poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestSimpleFileRead.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestSimpleFileRead.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestSimpleFileRead.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestSimpleFileRead.java Fri Jan  4 06:19:14 2008
@@ -67,6 +67,18 @@
 	}
 	
 	/**
+	 * Test to see if we can read the From Chunk.
+	 * @throws ChunkNotFoundException 
+	 * 
+	 */
+	public void testReadDisplayFrom() throws ChunkNotFoundException {
+		String obtained = mapiMessage.getDisplayFrom();
+		String expected = "Travis Ferguson";
+		
+		TestCase.assertEquals(obtained, expected);
+	}
+	
+	/**
 	 * Test to see if we can read the CC Chunk.
 	 * @throws ChunkNotFoundException 
 	 * 

Modified: poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
Binary files - no diff available.

Modified: poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/eval/TestEverything.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/eval/TestEverything.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/eval/TestEverything.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/eval/TestEverything.java Fri Jan  4 06:19:14 2008
@@ -23,27 +23,37 @@
 import junit.framework.TestSuite;
 
 /**
- * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
+ * This is a test of all the Eval functions we have implemented.
+ * Add newly implemented Eval functions in here to have them
+ *  tested.
+ * For newly implemented functions, 
+ *  @see org.apache.poi.hssf.record.formula.functions.TestEverything
  *
+ * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
  */
 public class TestEverything extends TestSuite {
 
     public static TestSuite suite() throws Exception {
         TestSuite suite = new TestSuite("Tests for OperationEval concrete implementation classes.");
-        suite.addTest(new GenericFormulaTestCase("D23"));
-        suite.addTest(new GenericFormulaTestCase("D27"));
-        suite.addTest(new GenericFormulaTestCase("D31"));
-        suite.addTest(new GenericFormulaTestCase("D35"));
-        suite.addTest(new GenericFormulaTestCase("D39"));
-        suite.addTest(new GenericFormulaTestCase("D43"));
-        suite.addTest(new GenericFormulaTestCase("D47"));
-        suite.addTest(new GenericFormulaTestCase("D51"));
-        suite.addTest(new GenericFormulaTestCase("D55"));
-        suite.addTest(new GenericFormulaTestCase("D59"));
-        suite.addTest(new GenericFormulaTestCase("D63"));
-        suite.addTest(new GenericFormulaTestCase("D67"));
-        suite.addTest(new GenericFormulaTestCase("D71"));
-        suite.addTest(new GenericFormulaTestCase("D75"));
+        suite.addTest(new GenericFormulaTestCase("D23")); // Add
+        suite.addTest(new GenericFormulaTestCase("D27")); // ConcatEval
+        suite.addTest(new GenericFormulaTestCase("D31")); // DivideEval
+        suite.addTest(new GenericFormulaTestCase("D35")); // EqualEval
+        suite.addTest(new GenericFormulaTestCase("D39")); // GreaterEqualEval
+        suite.addTest(new GenericFormulaTestCase("D43")); // GreaterThanEval
+        suite.addTest(new GenericFormulaTestCase("D47")); // LessEqualEval
+        suite.addTest(new GenericFormulaTestCase("D51")); // LessThanEval
+        suite.addTest(new GenericFormulaTestCase("D55")); // MultiplyEval
+        suite.addTest(new GenericFormulaTestCase("D59")); // NotEqualEval
+        suite.addTest(new GenericFormulaTestCase("D63")); // PowerEval
+        suite.addTest(new GenericFormulaTestCase("D67")); // SubtractEval
+        suite.addTest(new GenericFormulaTestCase("D71")); // UnaryMinusEval
+        suite.addTest(new GenericFormulaTestCase("D75")); // UnaryPlusEval
+        
+		// Add newly implemented Eval functions here
+		// (Formula functions go in 
+ 		//  @see org.apache.poi.hssf.record.formula.functions.TestEverything )
+        
         return suite;
     }
 }

Modified: poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestEverything.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestEverything.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestEverything.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestEverything.java Fri Jan  4 06:19:14 2008
@@ -25,11 +25,16 @@
 import junit.framework.TestSuite;
 
 /**
- * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
+ * This is a test of all the normal formula functions we have implemented.
+ * It should pick up newly implemented functions which are correctly added
+ *  to the test formula excel file, but tweak the rows below if you
+ *  add any past the end of what's currently checked.
+ * For newly implemented eval functions, 
+ *  @see org.apache.poi.hssf.record.formula.eval.TestEverything
  *
+ * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
  */
 public class TestEverything extends TestSuite {
-
     public static TestSuite suite() throws Exception {
         TestSuite suite = new TestSuite("Tests for individual function classes");
         String s;

Modified: poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/data/1900DateWindowing.xls
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/data/1900DateWindowing.xls?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
Binary files - no diff available.

Modified: poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/data/1904DateWindowing.xls
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/data/1904DateWindowing.xls?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
Binary files - no diff available.

Copied: poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/data/TestDataValidation.xls (from r608814, poi/trunk/src/testcases/org/apache/poi/hssf/data/TestDataValidation.xls)
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/data/TestDataValidation.xls?p2=poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/data/TestDataValidation.xls&p1=poi/trunk/src/testcases/org/apache/poi/hssf/data/TestDataValidation.xls&r1=608814&r2=608846&rev=608846&view=diff
==============================================================================
Binary files - no diff available.

Modified: poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java Fri Jan  4 06:19:14 2008
@@ -68,6 +68,19 @@
 		);
 	}
 	
+	public void testwithContinueRecords() throws Exception {
+		String path = System.getProperty("HSSF.testdata.path");
+		FileInputStream fin = new FileInputStream(path + File.separator + "StringContinueRecords.xls");
+		
+		ExcelExtractor extractor = new ExcelExtractor(new POIFSFileSystem(fin));
+		
+		extractor.getText();
+		
+		// Has masses of text
+		// Until we fixed bug #41064, this would've
+		//   failed by now
+		assertTrue(extractor.getText().length() > 40960);
+	}
 	
 	public void testStringConcat() throws Exception {
 		String path = System.getProperty("HSSF.testdata.path");

Modified: poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java Fri Jan  4 06:19:14 2008
@@ -44,6 +44,7 @@
  * paticular datatypes, etc.
  * @author Andrew C. Oliver (andy at superlinksoftware dot com)
  * @author  Dan Sherman (dsherman at isisph.com)
+ * @author Alex Jacoby (ajacoby at gmail.com)
  */
 
 public class TestHSSFCell
@@ -107,42 +108,106 @@
     }
 
     /**
-    * Checks that the recognition of files using 1904 date windowing
-    *  is working properly. Conversion of the date is also an issue,
-    *  but there's a separate unit test for that.
-    */
-    public void testDateWindowing() throws Exception {
-        GregorianCalendar cal = new GregorianCalendar(2000,0,1); // Jan. 1, 2000
-        Date date = cal.getTime();
-        String path = System.getProperty("HSSF.testdata.path");
-
-        // first check a file with 1900 Date Windowing
-        String filename = path + "/1900DateWindowing.xls";
-        FileInputStream stream   = new FileInputStream(filename);
-        POIFSFileSystem fs       = new POIFSFileSystem(stream);
-        HSSFWorkbook    workbook = new HSSFWorkbook(fs);
-        HSSFSheet       sheet    = workbook.getSheetAt(0);
-
-        assertEquals("Date from file using 1900 Date Windowing",
-                        date.getTime(),
-                           sheet.getRow(0).getCell((short)0)
-                              .getDateCellValue().getTime());
-        stream.close();
-        
-        // now check a file with 1904 Date Windowing
-        filename = path + "/1904DateWindowing.xls";
-        stream   = new FileInputStream(filename);
-        fs       = new POIFSFileSystem(stream);
-        workbook = new HSSFWorkbook(fs);
-        sheet    = workbook.getSheetAt(0);
-
-        assertEquals("Date from file using 1904 Date Windowing",
-                        date.getTime(),
-                           sheet.getRow(0).getCell((short)0)
-                              .getDateCellValue().getTime());
-        stream.close();
-    }
-    
+     * Checks that the recognition of files using 1904 date windowing
+     *  is working properly. Conversion of the date is also an issue,
+     *  but there's a separate unit test for that.
+     */
+     public void testDateWindowingRead() throws Exception {
+         GregorianCalendar cal = new GregorianCalendar(2000,0,1); // Jan. 1, 2000
+         Date date = cal.getTime();
+         String path = System.getProperty("HSSF.testdata.path");
+
+         // first check a file with 1900 Date Windowing
+         String filename = path + "/1900DateWindowing.xls";
+         FileInputStream stream   = new FileInputStream(filename);
+         POIFSFileSystem fs       = new POIFSFileSystem(stream);
+         HSSFWorkbook    workbook = new HSSFWorkbook(fs);
+         HSSFSheet       sheet    = workbook.getSheetAt(0);
+
+         assertEquals("Date from file using 1900 Date Windowing",
+                         date.getTime(),
+                            sheet.getRow(0).getCell((short)0)
+                               .getDateCellValue().getTime());
+         stream.close();
+         
+         // now check a file with 1904 Date Windowing
+         filename = path + "/1904DateWindowing.xls";
+         stream   = new FileInputStream(filename);
+         fs       = new POIFSFileSystem(stream);
+         workbook = new HSSFWorkbook(fs);
+         sheet    = workbook.getSheetAt(0);
+
+         assertEquals("Date from file using 1904 Date Windowing",
+                         date.getTime(),
+                            sheet.getRow(0).getCell((short)0)
+                               .getDateCellValue().getTime());
+         stream.close();
+     }
+
+     /**
+      * Checks that dates are properly written to both types of files:
+      * those with 1900 and 1904 date windowing.  Note that if the
+      * previous test ({@link #testDateWindowingRead}) fails, the
+      * results of this test are meaningless.
+      */
+      public void testDateWindowingWrite() throws Exception {
+          GregorianCalendar cal = new GregorianCalendar(2000,0,1); // Jan. 1, 2000
+          Date date = cal.getTime();
+          String path = System.getProperty("HSSF.testdata.path");
+
+          // first check a file with 1900 Date Windowing
+          String filename = path + "/1900DateWindowing.xls";
+          writeCell(filename, 0, (short) 1, date);          
+          assertEquals("Date from file using 1900 Date Windowing",
+                          date.getTime(),
+                          readCell(filename, 0, (short) 1).getTime());
+          
+          // now check a file with 1904 Date Windowing
+          filename = path + "/1904DateWindowing.xls";
+          writeCell(filename, 0, (short) 1, date);          
+          assertEquals("Date from file using 1900 Date Windowing",
+                          date.getTime(),
+                          readCell(filename, 0, (short) 1).getTime());
+      }
+
+      /**
+       * Sets cell value and writes file.
+       */
+      private void writeCell(String filename,
+     		 int rowIdx, short colIdx, Date date) throws Exception {
+          FileInputStream stream   = new FileInputStream(filename);
+          POIFSFileSystem fs       = new POIFSFileSystem(stream);
+          HSSFWorkbook    workbook = new HSSFWorkbook(fs);
+          HSSFSheet       sheet    = workbook.getSheetAt(0);
+          HSSFRow         row      = sheet.getRow(rowIdx);
+          HSSFCell        cell     = row.getCell(colIdx);
+          
+          if (cell == null) {
+        	  cell = row.createCell(colIdx);
+          }
+          cell.setCellValue(date);
+          
+          // Write the file
+          stream.close();
+          FileOutputStream oStream = new FileOutputStream(filename);
+          workbook.write(oStream);
+          oStream.close();
+      }
+      
+      /**
+       * Reads cell value from file.
+       */
+      private Date readCell(String filename,
+     		 int rowIdx, short colIdx) throws Exception {
+          FileInputStream stream   = new FileInputStream(filename);
+          POIFSFileSystem fs       = new POIFSFileSystem(stream);
+          HSSFWorkbook    workbook = new HSSFWorkbook(fs);
+          HSSFSheet       sheet    = workbook.getSheetAt(0);
+          HSSFRow         row      = sheet.getRow(rowIdx);
+          HSSFCell        cell     = row.getCell(colIdx);
+          return cell.getDateCellValue();
+      }
+      
     /**
      * Tests that the active cell can be correctly read and set
      */

Modified: poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java Fri Jan  4 06:19:14 2008
@@ -85,4 +85,23 @@
             assertEquals(anchor[i].getRow2(), record.getRow2());
         }
     }
+
+    public void testAnchorHeightInPoints(){
+        HSSFWorkbook wb = new HSSFWorkbook();
+        HSSFSheet sheet = wb.createSheet();
+
+        HSSFClientAnchor[] anchor = {
+            new HSSFClientAnchor( 0 , 0,    0 , 0 ,(short)0, 1,(short)1, 3),
+            new HSSFClientAnchor( 0 , 254 , 0 , 126 ,(short)0, 1,(short)1, 3),
+            new HSSFClientAnchor( 0 , 128 , 0 , 128 ,(short)0, 1,(short)1, 3),
+            new HSSFClientAnchor( 0 , 0 , 0 , 128 ,(short)0, 1,(short)1, 3),
+        };
+        float[] ref = {24.0f, 18.0f, 24.0f, 30.0f};
+        for (int i = 0; i < anchor.length; i++) {
+            float height = anchor[i].getAnchorHeightInPoints(sheet);
+            assertEquals(ref[i], height, 0);
+        }
+
+    }
+
 }

Modified: poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java Fri Jan  4 06:19:14 2008
@@ -36,6 +36,8 @@
  *
  * @author  Dan Sherman (dsherman at isisph.com)
  * @author  Hack Kampbjorn (hak at 2mba.dk)
+ * @author  Pavel Krupets (pkrupets at palmtreebusiness dot com)
+ * @author Alex Jacoby (ajacoby at gmail.com)
  * @version %I%, %G%
  */
 
@@ -47,7 +49,9 @@
 	public static final int CALENDAR_FEBRUARY = 1;
 	public static final int CALENDAR_MARCH = 2;
 	public static final int CALENDAR_APRIL = 3;
-
+	public static final int CALENDAR_JULY = 6;
+    public static final int CALENDAR_OCTOBER = 9;
+    
     public TestHSSFDateUtil(String s)
     {
         super(s);
@@ -67,10 +71,10 @@
             GregorianCalendar date      = new GregorianCalendar(2002, 0, 1,
                     hour, 1, 1);
             double            excelDate =
-                    HSSFDateUtil.getExcelDate(date.getTime());
+                    HSSFDateUtil.getExcelDate(date.getTime(), false);
 
             assertEquals("Checking hour = " + hour, date.getTime().getTime(),
-                    HSSFDateUtil.getJavaDate(excelDate).getTime());
+                    HSSFDateUtil.getJavaDate(excelDate, false).getTime());
         }
 
         // check 1900 and 1904 date windowing conversions
@@ -99,7 +103,7 @@
     public void testExcelConversionOnDSTStart() {
         TimeZone cet = TimeZone.getTimeZone("Europe/Copenhagen");
         TimeZone.setDefault(cet);
-        Calendar cal = new GregorianCalendar(2004, Calendar.MARCH, 28);
+        Calendar cal = new GregorianCalendar(2004, CALENDAR_MARCH, 28);
         for (int hour = 0; hour < 24; hour++) {
 
             // Skip 02:00 CET as that is the Daylight change time
@@ -110,7 +114,7 @@
 
             cal.set(Calendar.HOUR_OF_DAY, hour);
             Date javaDate = cal.getTime();
-            double excelDate = HSSFDateUtil.getExcelDate(javaDate);
+            double excelDate = HSSFDateUtil.getExcelDate(javaDate, false);
             double difference = excelDate - Math.floor(excelDate);
             int differenceInHours = (int) (difference * 24 * 60 + 0.5) / 60;
             assertEquals("Checking " + hour + " hour on Daylight Saving Time start date",
@@ -118,7 +122,7 @@
                     differenceInHours);
             assertEquals("Checking " + hour + " hour on Daylight Saving Time start date",
                     javaDate.getTime(),
-                    HSSFDateUtil.getJavaDate(excelDate).getTime());
+                    HSSFDateUtil.getJavaDate(excelDate, false).getTime());
         }
     }
 
@@ -129,8 +133,8 @@
     public void testJavaConversionOnDSTStart() {
         TimeZone cet = TimeZone.getTimeZone("Europe/Copenhagen");
         TimeZone.setDefault(cet);
-        Calendar cal = new GregorianCalendar(2004, Calendar.MARCH, 28);
-        double excelDate = HSSFDateUtil.getExcelDate(cal.getTime());
+        Calendar cal = new GregorianCalendar(2004, CALENDAR_MARCH, 28);
+        double excelDate = HSSFDateUtil.getExcelDate(cal.getTime(), false);
         double oneHour = 1.0 / 24;
         double oneMinute = oneHour / 60;
         for (int hour = 0; hour < 24; hour++, excelDate += oneHour) {
@@ -142,10 +146,10 @@
             }
 
             cal.set(Calendar.HOUR_OF_DAY, hour);
-            Date javaDate = HSSFDateUtil.getJavaDate(excelDate);
+            Date javaDate = HSSFDateUtil.getJavaDate(excelDate, false);
             assertEquals("Checking " + hour + " hours on Daylight Saving Time start date",
                     excelDate,
-                    HSSFDateUtil.getExcelDate(javaDate), oneMinute);
+                    HSSFDateUtil.getExcelDate(javaDate, false), oneMinute);
         }
     }
 
@@ -156,11 +160,11 @@
     public void testExcelConversionOnDSTEnd() {
         TimeZone cet = TimeZone.getTimeZone("Europe/Copenhagen");
         TimeZone.setDefault(cet);
-        Calendar cal = new GregorianCalendar(2004, Calendar.OCTOBER, 31);
+        Calendar cal = new GregorianCalendar(2004, CALENDAR_OCTOBER, 31);
         for (int hour = 0; hour < 24; hour++) {
             cal.set(Calendar.HOUR_OF_DAY, hour);
             Date javaDate = cal.getTime();
-            double excelDate = HSSFDateUtil.getExcelDate(javaDate);
+            double excelDate = HSSFDateUtil.getExcelDate(javaDate, false);
             double difference = excelDate - Math.floor(excelDate);
             int differenceInHours = (int) (difference * 24 * 60 + 0.5) / 60;
             assertEquals("Checking " + hour + " hour on Daylight Saving Time end date",
@@ -168,7 +172,7 @@
                     differenceInHours);
             assertEquals("Checking " + hour + " hour on Daylight Saving Time start date",
                     javaDate.getTime(),
-                    HSSFDateUtil.getJavaDate(excelDate).getTime());
+                    HSSFDateUtil.getJavaDate(excelDate, false).getTime());
         }
     }
 
@@ -179,16 +183,16 @@
     public void testJavaConversionOnDSTEnd() {
         TimeZone cet = TimeZone.getTimeZone("Europe/Copenhagen");
         TimeZone.setDefault(cet);
-        Calendar cal = new GregorianCalendar(2004, Calendar.OCTOBER, 31);
-        double excelDate = HSSFDateUtil.getExcelDate(cal.getTime());
+        Calendar cal = new GregorianCalendar(2004, CALENDAR_OCTOBER, 31);
+        double excelDate = HSSFDateUtil.getExcelDate(cal.getTime(), false);
         double oneHour = 1.0 / 24;
         double oneMinute = oneHour / 60;
         for (int hour = 0; hour < 24; hour++, excelDate += oneHour) {
             cal.set(Calendar.HOUR_OF_DAY, hour);
-            Date javaDate = HSSFDateUtil.getJavaDate(excelDate);
+            Date javaDate = HSSFDateUtil.getJavaDate(excelDate, false);
             assertEquals("Checking " + hour + " hours on Daylight Saving Time start date",
                     excelDate,
-                    HSSFDateUtil.getExcelDate(javaDate), oneMinute);
+                    HSSFDateUtil.getExcelDate(javaDate, false), oneMinute);
         }
     }
     
@@ -315,25 +319,38 @@
     }
     
     public void testDateBug_2Excel() {
-        assertEquals(59.0, HSSFDateUtil.getExcelDate(createDate(1900, CALENDAR_FEBRUARY, 28)), 0.00001);
-        assertEquals(61.0, HSSFDateUtil.getExcelDate(createDate(1900, CALENDAR_MARCH, 1)), 0.00001);
+        assertEquals(59.0, HSSFDateUtil.getExcelDate(createDate(1900, CALENDAR_FEBRUARY, 28), false), 0.00001);
+        assertEquals(61.0, HSSFDateUtil.getExcelDate(createDate(1900, CALENDAR_MARCH, 1), false), 0.00001);
 
-        assertEquals(37315.00, HSSFDateUtil.getExcelDate(createDate(2002, CALENDAR_FEBRUARY, 28)), 0.00001);
-        assertEquals(37316.00, HSSFDateUtil.getExcelDate(createDate(2002, CALENDAR_MARCH, 1)), 0.00001);
-        assertEquals(37257.00, HSSFDateUtil.getExcelDate(createDate(2002, CALENDAR_JANUARY, 1)), 0.00001);
-        assertEquals(38074.00, HSSFDateUtil.getExcelDate(createDate(2004, CALENDAR_MARCH, 28)), 0.00001);
+        assertEquals(37315.00, HSSFDateUtil.getExcelDate(createDate(2002, CALENDAR_FEBRUARY, 28), false), 0.00001);
+        assertEquals(37316.00, HSSFDateUtil.getExcelDate(createDate(2002, CALENDAR_MARCH, 1), false), 0.00001);
+        assertEquals(37257.00, HSSFDateUtil.getExcelDate(createDate(2002, CALENDAR_JANUARY, 1), false), 0.00001);
+        assertEquals(38074.00, HSSFDateUtil.getExcelDate(createDate(2004, CALENDAR_MARCH, 28), false), 0.00001);
     }
     
     public void testDateBug_2Java() {
-        assertEquals(createDate(1900, Calendar.FEBRUARY, 28), HSSFDateUtil.getJavaDate(59.0));
-        assertEquals(createDate(1900, Calendar.MARCH, 1), HSSFDateUtil.getJavaDate(61.0));
+        assertEquals(createDate(1900, CALENDAR_FEBRUARY, 28), HSSFDateUtil.getJavaDate(59.0, false));
+        assertEquals(createDate(1900, CALENDAR_MARCH, 1), HSSFDateUtil.getJavaDate(61.0, false));
         
-        assertEquals(createDate(2002, Calendar.FEBRUARY, 28), HSSFDateUtil.getJavaDate(37315.00));
-        assertEquals(createDate(2002, Calendar.MARCH, 1), HSSFDateUtil.getJavaDate(37316.00));
-        assertEquals(createDate(2002, Calendar.JANUARY, 1), HSSFDateUtil.getJavaDate(37257.00));
-        assertEquals(createDate(2004, Calendar.MARCH, 28), HSSFDateUtil.getJavaDate(38074.00));
+        assertEquals(createDate(2002, CALENDAR_FEBRUARY, 28), HSSFDateUtil.getJavaDate(37315.00, false));
+        assertEquals(createDate(2002, CALENDAR_MARCH, 1), HSSFDateUtil.getJavaDate(37316.00, false));
+        assertEquals(createDate(2002, CALENDAR_JANUARY, 1), HSSFDateUtil.getJavaDate(37257.00, false));
+        assertEquals(createDate(2004, CALENDAR_MARCH, 28), HSSFDateUtil.getJavaDate(38074.00, false));
     }
-
+    
+    public void testDate1904() {
+        assertEquals(createDate(1904, CALENDAR_JANUARY, 2), HSSFDateUtil.getJavaDate(1.0, true));
+        assertEquals(createDate(1904, CALENDAR_JANUARY, 1), HSSFDateUtil.getJavaDate(0.0, true));
+        assertEquals(0.0, HSSFDateUtil.getExcelDate(createDate(1904, CALENDAR_JANUARY, 1), true), 0.00001);
+        assertEquals(1.0, HSSFDateUtil.getExcelDate(createDate(1904, CALENDAR_JANUARY, 2), true), 0.00001);
+        
+        assertEquals(createDate(1998, CALENDAR_JULY, 5), HSSFDateUtil.getJavaDate(35981, false));
+        assertEquals(createDate(1998, CALENDAR_JULY, 5), HSSFDateUtil.getJavaDate(34519, true));
+        
+        assertEquals(35981.0, HSSFDateUtil.getExcelDate(createDate(1998, CALENDAR_JULY, 5), false), 0.00001);
+        assertEquals(34519.0, HSSFDateUtil.getExcelDate(createDate(1998, CALENDAR_JULY, 5), true), 0.00001);
+    }
+    
     private Date createDate(int year, int month, int day) {
         Calendar c = new GregorianCalendar();
         c.set(year, month, day, 0, 0, 0);
@@ -341,10 +358,21 @@
         return c.getTime();
     }
     
+    /**
+     * Check if HSSFDateUtil.getAbsoluteDay works as advertised.
+     */
+    public void testAbsoluteDay() {
+        // 1 Jan 1900 is 1 day after 31 Dec 1899
+        GregorianCalendar calendar = new GregorianCalendar(1900, 0, 1);
+        assertEquals("Checking absolute day (1 Jan 1900)", 1, HSSFDateUtil.absoluteDay(calendar, false));
+        // 1 Jan 1901 is 366 days after 31 Dec 1899
+        calendar = new GregorianCalendar(1901, 0, 1);
+        assertEquals("Checking absolute day (1 Jan 1901)", 366, HSSFDateUtil.absoluteDay(calendar, false));
+    }
+    
     public static void main(String [] args) {
         System.out
                 .println("Testing org.apache.poi.hssf.usermodel.TestHSSFDateUtil");
         junit.textui.TestRunner.run(TestHSSFDateUtil.class);
     }
 }
-

Modified: poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java Fri Jan  4 06:19:14 2008
@@ -96,6 +96,71 @@
     }
     
     /**
+     * Uses the palette from cell stylings
+     */
+    public void testPaletteFromCellColours() throws Exception {
+        String dir = System.getProperty("HSSF.testdata.path");
+        File sample = new File(dir + "/SimpleWithColours.xls");
+        assertTrue("SimpleWithColours.xls exists and is readable", sample.canRead());
+        FileInputStream fis = new FileInputStream(sample);
+        HSSFWorkbook book = new HSSFWorkbook(fis);
+        fis.close();
+    	
+        HSSFPalette p = book.getCustomPalette();
+        
+        HSSFCell cellA = book.getSheetAt(0).getRow(0).getCell((short)0);
+        HSSFCell cellB = book.getSheetAt(0).getRow(1).getCell((short)0);
+        HSSFCell cellC = book.getSheetAt(0).getRow(2).getCell((short)0);
+        HSSFCell cellD = book.getSheetAt(0).getRow(3).getCell((short)0);
+        HSSFCell cellE = book.getSheetAt(0).getRow(4).getCell((short)0);
+        
+        // Plain
+        assertEquals("I'm plain", cellA.getStringCellValue());
+        assertEquals(64, cellA.getCellStyle().getFillForegroundColor());
+        assertEquals(64, cellA.getCellStyle().getFillBackgroundColor());
+        assertEquals(HSSFFont.COLOR_NORMAL, cellA.getCellStyle().getFont(book).getColor());
+        assertEquals(0, cellA.getCellStyle().getFillPattern());
+        assertEquals("0:0:0", p.getColor((short)64).getHexString());
+        assertEquals(null, p.getColor((short)32767));
+        
+        // Red
+        assertEquals("I'm red", cellB.getStringCellValue());
+        assertEquals(64, cellB.getCellStyle().getFillForegroundColor());
+        assertEquals(64, cellB.getCellStyle().getFillBackgroundColor());
+        assertEquals(10, cellB.getCellStyle().getFont(book).getColor());
+        assertEquals(0, cellB.getCellStyle().getFillPattern());
+        assertEquals("0:0:0", p.getColor((short)64).getHexString());
+        assertEquals("FFFF:0:0", p.getColor((short)10).getHexString());
+        
+        // Red + green bg
+        assertEquals("I'm red with a green bg", cellC.getStringCellValue());
+        assertEquals(11, cellC.getCellStyle().getFillForegroundColor());
+        assertEquals(64, cellC.getCellStyle().getFillBackgroundColor());
+        assertEquals(10, cellC.getCellStyle().getFont(book).getColor());
+        assertEquals(1, cellC.getCellStyle().getFillPattern());
+        assertEquals("0:FFFF:0", p.getColor((short)11).getHexString());
+        assertEquals("FFFF:0:0", p.getColor((short)10).getHexString());
+        
+        // Pink with yellow
+        assertEquals("I'm pink with a yellow pattern (none)", cellD.getStringCellValue());
+        assertEquals(13, cellD.getCellStyle().getFillForegroundColor());
+        assertEquals(64, cellD.getCellStyle().getFillBackgroundColor());
+        assertEquals(14, cellD.getCellStyle().getFont(book).getColor());
+        assertEquals(0, cellD.getCellStyle().getFillPattern());
+        assertEquals("FFFF:FFFF:0", p.getColor((short)13).getHexString());
+        assertEquals("FFFF:0:FFFF", p.getColor((short)14).getHexString());
+        
+        // Pink with yellow - full
+        assertEquals("I'm pink with a yellow pattern (full)", cellE.getStringCellValue());
+        assertEquals(13, cellE.getCellStyle().getFillForegroundColor());
+        assertEquals(64, cellE.getCellStyle().getFillBackgroundColor());
+        assertEquals(14, cellE.getCellStyle().getFont(book).getColor());
+        assertEquals(0, cellE.getCellStyle().getFillPattern());
+        assertEquals("FFFF:FFFF:0", p.getColor((short)13).getHexString());
+        assertEquals("FFFF:0:FFFF", p.getColor((short)14).getHexString());
+    }
+    
+    /**
      * Verifies that the generated gnumeric-format string values match the
      * hardcoded values in the HSSFColor default color palette
      */

Modified: poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java Fri Jan  4 06:19:14 2008
@@ -63,7 +63,7 @@
         //System.out.println("first assertion for date");
         assertEquals(new GregorianCalendar(2000, 0, 1, 10, 51, 2).getTime(),
                      HSSFDateUtil
-                         .getJavaDate(firstCell.getNumericCellValue()));
+                         .getJavaDate(firstCell.getNumericCellValue(), false));
         HSSFRow  row  = sheet.createRow(( short ) 15);
         HSSFCell cell = row.createCell(( short ) 1);
 

Modified: poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java?rev=608846&r1=608845&r2=608846&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java (original)
+++ poi/tags/REL_3_0_2_BETA2/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java Fri Jan  4 06:19:14 2008
@@ -23,6 +23,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.poifs.filesystem.POIFSWriterEvent;
 import org.apache.poi.poifs.filesystem.POIFSWriterListener;
@@ -140,4 +141,28 @@
     fs.writeFilesystem(out);
     new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
   }
+
+  public void testEmptyDocumentBug11744() throws Exception {
+        byte[] testData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+
+        POIFSFileSystem fs = new POIFSFileSystem();
+        fs.createDocument(new ByteArrayInputStream(new byte[0]), "Empty");
+        fs.createDocument(new ByteArrayInputStream(testData), "NotEmpty");
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        fs.writeFilesystem(out);
+        out.toByteArray();
+
+        // This line caused the error.
+        fs = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
+
+        DocumentEntry entry = (DocumentEntry) fs.getRoot().getEntry("Empty");
+        assertEquals("Expected zero size", 0, entry.getSize());
+        assertEquals("Expected zero read from stream", 0,
+                     IOUtils.toByteArray(new DocumentInputStream(entry)).length);
+
+        entry = (DocumentEntry) fs.getRoot().getEntry("NotEmpty");
+        assertEquals("Expected size was wrong", testData.length, entry.getSize());
+        assertEquals("Expected different data read from stream", testData,
+                     IOUtils.toByteArray(new DocumentInputStream(entry)));
+    }
 }



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