poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r670186 [7/7] - in /poi/tags/REL_3_1_FINAL: ./ legal/ src/documentation/content/xdocs/ src/examples/src/org/apache/poi/hslf/ src/examples/src/org/apache/poi/hslf/usermodel/ src/examples/src/org/apache/poi/hslf/usermodel/examples/ src/java/o...
Date Sat, 21 Jun 2008 12:03:49 GMT
Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java Sat Jun 21 05:03:44 2008
@@ -26,9 +26,12 @@
 import java.io.OutputStream;
 import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
+import java.math.BigInteger;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -37,7 +40,6 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.Stack;
-import java.util.zip.CRC32;
 import java.util.zip.ZipException;
 import java.util.zip.ZipFile;
 
@@ -149,7 +151,6 @@
 	
 	private static final class FunctionDataCollector {
 
-
 		private final Map _allFunctionsByIndex;
 		private final Map _allFunctionsByName;
 		private final Set _groupFunctionIndexes;
@@ -184,25 +185,29 @@
 			_allFunctionsByName.put(funcName, fd);
 		}
 
+		/**
+		 * Some extra validation here.
+		 * Any function which changes definition will have a footnote in the source document
+		 */
 		private void checkRedefinedFunction(boolean hasNote, String funcName, Integer funcIxKey) {
 			FunctionData fdPrev;
+			// check by index
 			fdPrev = (FunctionData) _allFunctionsByIndex.get(funcIxKey);
 			if(fdPrev != null) {
-				if(fdPrev.hasFootnote() && hasNote) {
-					// func def can change if both have a foot-note
-					_allFunctionsByName.remove(fdPrev.getName());
-				} else {
-					throw new RuntimeException("changing function definition without foot-note");
+				if(!fdPrev.hasFootnote() || !hasNote) {
+					throw new RuntimeException("changing function [" 
+							+ funcIxKey + "] definition without foot-note");
 				}
+				_allFunctionsByName.remove(fdPrev.getName());
 			}
+			// check by name
 			fdPrev = (FunctionData) _allFunctionsByName.get(funcName);
 			if(fdPrev != null) {
-				if(fdPrev.hasFootnote() && hasNote) {
-					// func def can change if both have a foot-note
-					_allFunctionsByIndex.remove(new Integer(fdPrev.getIndex()));
-				} else {
-					throw new RuntimeException("changing function definition without foot-note");
+				if(!fdPrev.hasFootnote() || !hasNote) {
+					throw new RuntimeException("changing function '" 
+							+ funcName + "' definition without foot-note");
 				}
+				_allFunctionsByIndex.remove(new Integer(fdPrev.getIndex()));
 			}
 		}
 
@@ -237,9 +242,13 @@
 		private static final String[] TABLE_CELL_RELPATH_NAMES = {
 			"table:table-row", "table:table-cell", "text:p",	
 		};
-		private static final String[] NOTE_REF_RELPATH_NAMES = {
+		// after May 2008 there was one more style applied to the footnotes
+		private static final String[] NOTE_REF_RELPATH_NAMES_OLD = { 
 			"table:table-row", "table:table-cell", "text:p", "text:span", "text:note-ref",
 		};
+		private static final String[] NOTE_REF_RELPATH_NAMES = {
+			"table:table-row", "table:table-cell", "text:p", "text:span", "text:span", "text:note-ref",
+		};
 
 
 		private final Stack _elemNameStack;
@@ -368,6 +377,8 @@
 			} else if(matchesRelPath(TABLE_CELL_RELPATH_NAMES)) {
 				_textNodeBuffer.setLength(0);
 				_cellHasNote = false;
+			} else if(matchesRelPath(NOTE_REF_RELPATH_NAMES_OLD)) {
+				_cellHasNote = true;
 			} else if(matchesRelPath(NOTE_REF_RELPATH_NAMES)) {
 				_cellHasNote = true;
 			}
@@ -456,6 +467,9 @@
 	}
 
 	private static void processFile(File effDocFile, File outFile) {
+		if(!effDocFile.exists()) {
+			throw new RuntimeException("file '" + effDocFile.getAbsolutePath() + "' does not exist");
+		}
 		OutputStream os;
 		try {
 			os = new FileOutputStream(outFile);
@@ -475,7 +489,7 @@
 		ps.println("# Created by (" + genClass.getName() + ")");
 		// identify the source file
 		ps.print("# from source file '" + SOURCE_DOC_FILE_NAME + "'");
-		ps.println(" (size=" + effDocFile.length() + ", crc=" + getFileCRC(effDocFile) + ")");
+		ps.println(" (size=" + effDocFile.length() + ", md5=" + getFileMD5(effDocFile) + ")");
 		ps.println("#");
 		ps.println("#Columns: (index, name, minParams, maxParams, returnClass, paramClasses, isVolatile, hasFootnote )");
 		ps.println("");
@@ -490,6 +504,14 @@
 			throw new RuntimeException(e);
 		}
 		ps.close();
+		
+		String canonicalOutputFileName;
+		try {
+			canonicalOutputFileName = outFile.getCanonicalPath();
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+		System.out.println("Successfully output to '" + canonicalOutputFileName + "'");
 	}
 
 	private static void outputLicenseHeader(PrintStream ps) {
@@ -519,8 +541,14 @@
 	/**
 	 * Helps identify the source file
 	 */
-	private static String getFileCRC(File f) {
-		CRC32 crc = new CRC32();
+	private static String getFileMD5(File f) {
+		MessageDigest m;
+		try {
+			m = MessageDigest.getInstance("MD5");
+		} catch (NoSuchAlgorithmException e) {
+			throw new RuntimeException(e);
+		}
+
 		byte[]buf = new byte[2048];
 		try {
 			InputStream is = new FileInputStream(f);
@@ -529,21 +557,17 @@
 				if(bytesRead<1) { 
 					break;
 				}
-				crc.update(buf, 0, bytesRead);
+				m.update(buf, 0, bytesRead);
 			}
 			is.close();
 		} catch (IOException e) {
 			throw new RuntimeException(e);
 		}
-		return "0x" + Long.toHexString(crc.getValue()).toUpperCase();
+		
+		return "0x" + new BigInteger(1, m.digest()).toString(16);
 	}
 
-	private static File getSourceFile() {
-		if (false) {
-			File dir = new File("c:/temp");
-			File effDocFile = new File(dir, SOURCE_DOC_FILE_NAME);
-			return effDocFile;
-		}
+	private static File downloadSourceFile() {
 		URL url;
 		try {
 			url = new URL("http://sc.openoffice.org/" + SOURCE_DOC_FILE_NAME);
@@ -557,7 +581,7 @@
 			URLConnection conn = url.openConnection();
 			InputStream is = conn.getInputStream();
 			System.out.println("downloading " + url.toExternalForm());
-			result = File.createTempFile("excelfileformat", "odt");
+			result = File.createTempFile("excelfileformat", ".odt");
 			OutputStream os = new FileOutputStream(result);
 			while(true) {
 				int bytesRead = is.read(buf);
@@ -577,12 +601,17 @@
 
 	public static void main(String[] args) {
 
-		File effDocFile = getSourceFile();
-		if(!effDocFile.exists()) {
-			throw new RuntimeException("file '" + effDocFile.getAbsolutePath() + "' does not exist");
-		}
-
 		File outFile = new File("functionMetadata-asGenerated.txt");
-		processFile(effDocFile, outFile);
+
+		if (false) { // set true to use local file
+			File dir = new File("c:/temp");
+			File effDocFile = new File(dir, SOURCE_DOC_FILE_NAME);
+			processFile(effDocFile, outFile);
+			return;
+		}
+		
+		File tempEFFDocFile = downloadSourceFile();
+		processFile(tempEFFDocFile, outFile);
+		tempEFFDocFile.delete();
 	}
 }

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java Sat Jun 21 05:03:44 2008
@@ -21,7 +21,6 @@
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.model.FormulaParser;
-import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.formula.AbstractFunctionPtg;
 import org.apache.poi.hssf.record.formula.FuncPtg;
 import org.apache.poi.hssf.record.formula.FuncVarPtg;
@@ -29,7 +28,7 @@
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 /**
  * Tests parsing of some built-in functions that were not properly
- * registered in POI as bug #44675, #44733 (March/April 2008).
+ * registered in POI as of bug #44675, #44733 (March/April 2008).
  * 
  * @author Josh Micich
  */
@@ -76,7 +75,7 @@
 	}
 	
 	public void testUsdollar() {
-		confirmFunc("USDOLLAR(1)", 2, false, 204);
+		confirmFunc("USDOLLAR(1)", 2, true, 204);
 	}
 
 	public void testDBCS() {

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java Sat Jun 21 05:03:44 2008
@@ -17,22 +17,18 @@
 
 package org.apache.poi.hssf.record.formula.function;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
 
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
 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;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
 /**
  * Tests reading from a sample spreadsheet some built-in functions that were not properly
- * registered in POI as bug #44675, #44733 (March/April 2008).
+ * registered in POI as of bug #44675, #44733 (March/April 2008).
  * 
  * @author Josh Micich
  */

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/EvalFactory.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/EvalFactory.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/EvalFactory.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/EvalFactory.java Sat Jun 21 05:03:44 2008
@@ -19,7 +19,7 @@
 package org.apache.poi.hssf.record.formula.functions;
 
 import org.apache.poi.hssf.record.formula.AreaPtg;
-import org.apache.poi.hssf.record.formula.ReferencePtg;
+import org.apache.poi.hssf.record.formula.RefPtg;
 import org.apache.poi.hssf.record.formula.eval.Area2DEval;
 import org.apache.poi.hssf.record.formula.eval.AreaEval;
 import org.apache.poi.hssf.record.formula.eval.NumberEval;
@@ -58,6 +58,6 @@
 	 * Creates a single RefEval (with value zero)
 	 */
 	public static RefEval createRefEval(String refStr) {
-		return new Ref2DEval(new ReferencePtg(refStr), ZERO);
+		return new Ref2DEval(new RefPtg(refStr), ZERO);
 	}
 }

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java Sat Jun 21 05:03:44 2008
@@ -21,7 +21,7 @@
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.record.formula.AreaPtg;
-import org.apache.poi.hssf.record.formula.ReferencePtg;
+import org.apache.poi.hssf.record.formula.RefPtg;
 import org.apache.poi.hssf.record.formula.eval.Area2DEval;
 import org.apache.poi.hssf.record.formula.eval.AreaEval;
 import org.apache.poi.hssf.record.formula.eval.BlankEval;
@@ -124,7 +124,7 @@
 		};
 		Area2DEval arg0 = new Area2DEval(new AreaPtg("C1:C6"), values);
 		
-		Ref2DEval criteriaArg = new Ref2DEval(new ReferencePtg("A1"), new NumberEval(25));
+		Ref2DEval criteriaArg = new Ref2DEval(new RefPtg("A1"), new NumberEval(25));
 		Eval[] args=  { arg0, criteriaArg, };
 		
 		double actual = NumericFunctionInvoker.invoke(new Countif(), args);

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/TestMid.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/TestMid.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/TestMid.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/TestMid.java Sat Jun 21 05:03:44 2008
@@ -18,7 +18,7 @@
 package org.apache.poi.hssf.record.formula.functions;
 
 import org.apache.poi.hssf.record.formula.AreaPtg;
-import org.apache.poi.hssf.record.formula.ReferencePtg;
+import org.apache.poi.hssf.record.formula.RefPtg;
 import org.apache.poi.hssf.record.formula.eval.Area2DEval;
 import org.apache.poi.hssf.record.formula.eval.AreaEval;
 import org.apache.poi.hssf.record.formula.eval.BlankEval;
@@ -77,7 +77,7 @@
 		
 		// startPos is 1x1 area ref, numChars is cell ref
 		AreaEval aeStart = new Area2DEval(new AreaPtg("A1:A1"), new ValueEval[] { new NumberEval(2), } );
-		RefEval reNumChars = new Ref2DEval(new ReferencePtg("B1"), new NumberEval(3));
+		RefEval reNumChars = new Ref2DEval(new RefPtg("B1"), new NumberEval(3));
 		confirmMid(new StringEval("galactic"), aeStart, reNumChars, "ala");
 
 		confirmMid(new StringEval("galactic"), new NumberEval(3.1), BlankEval.INSTANCE, "");

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/TestSumproduct.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/TestSumproduct.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/TestSumproduct.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/TestSumproduct.java Sat Jun 21 05:03:44 2008
@@ -17,7 +17,7 @@
 
 package org.apache.poi.hssf.record.formula.functions;
 
-import org.apache.poi.hssf.record.formula.ReferencePtg;
+import org.apache.poi.hssf.record.formula.RefPtg;
 import org.apache.poi.hssf.record.formula.eval.AreaEval;
 import org.apache.poi.hssf.record.formula.eval.ErrorEval;
 import org.apache.poi.hssf.record.formula.eval.Eval;
@@ -50,7 +50,7 @@
 
 	public void testScalarSimple() {
 		
-		RefEval refEval = new Ref2DEval(new ReferencePtg("A1"), new NumberEval(3));
+		RefEval refEval = new Ref2DEval(new RefPtg("A1"), new NumberEval(3));
 		Eval[] args = {
 			refEval, 
 			new NumberEval(2),

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java Sat Jun 21 05:03:44 2008
@@ -17,7 +17,7 @@
 
 package org.apache.poi.hssf.record.formula.functions;
 
-import org.apache.poi.hssf.record.formula.ReferencePtg;
+import org.apache.poi.hssf.record.formula.RefPtg;
 import org.apache.poi.hssf.record.formula.eval.BlankEval;
 import org.apache.poi.hssf.record.formula.eval.BoolEval;
 import org.apache.poi.hssf.record.formula.eval.ErrorEval;
@@ -50,7 +50,7 @@
 	 * where cell A1 has the specified innerValue
 	 */
 	private Eval invokeTWithReference(ValueEval innerValue) {
-		Eval arg = new Ref2DEval(new ReferencePtg((short)1, (short)1, false, false), innerValue);
+		Eval arg = new Ref2DEval(new RefPtg((short)1, (short)1, false, false), innerValue);
 		return invokeT(arg);
 	}
 	

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java Sat Jun 21 05:03:44 2008
@@ -28,7 +28,7 @@
 public class AllUserModelTests {
 	
 	public static Test suite() {
-		TestSuite result = new TestSuite("Tests for org.apache.poi.hssf.usermodel");
+		TestSuite result = new TestSuite(AllUserModelTests.class.getName());
 		
 		result.addTestSuite(TestBugs.class);
 		result.addTestSuite(TestCellStyle.class);
@@ -58,6 +58,7 @@
 		result.addTestSuite(TestHSSFSheetSetOrder.class);
 		result.addTestSuite(TestHSSFTextbox.class);
 		result.addTestSuite(TestHSSFWorkbook.class);
+		result.addTestSuite(TestLinkTable.class);
 		result.addTestSuite(TestNamedRange.class);
 		result.addTestSuite(TestOLE2Embeding.class);
 		result.addTestSuite(TestPOIFSProperties.class);

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Sat Jun 21 05:03:44 2008
@@ -18,14 +18,20 @@
 package org.apache.poi.hssf.usermodel;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.List;
 
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.record.EmbeddedObjectRefSubRecord;
+import org.apache.poi.hssf.record.NameRecord;
+import org.apache.poi.hssf.record.formula.DeletedArea3DPtg;
 import org.apache.poi.hssf.util.Region;
 import org.apache.poi.util.TempFile;
 
@@ -950,4 +956,99 @@
         writeOutAndReadBack(wb);
         assertTrue("no errors writing sample xls", true);
     }
+    
+    /**
+     * Problems with extracting check boxes from
+     *  HSSFObjectData
+     * @throws Exception
+     */
+    public void test44840() throws Exception {
+        HSSFWorkbook wb = openSample("WithCheckBoxes.xls");
+
+        // Take a look at the embeded objects
+        List objects = wb.getAllEmbeddedObjects();
+        assertEquals(1, objects.size());
+        
+        HSSFObjectData obj = (HSSFObjectData)objects.get(0);
+        assertNotNull(obj);
+        
+        // Peek inside the underlying record
+        EmbeddedObjectRefSubRecord rec = obj.findObjectRecord();
+        assertNotNull(rec);
+        
+        assertEquals(32, rec.field_1_stream_id_offset);
+        assertEquals(0, rec.field_6_stream_id); // WRONG!
+        assertEquals("Forms.CheckBox.1", rec.field_5_ole_classname);
+        assertEquals(12, rec.remainingBytes.length);
+        
+        // Doesn't have a directory
+        assertFalse(obj.hasDirectoryEntry());
+        assertNotNull(obj.getObjectData());
+        assertEquals(12, obj.getObjectData().length);
+        assertEquals("Forms.CheckBox.1", obj.getOLE2ClassName());
+        
+        try {
+        	obj.getDirectory();
+        	fail();
+        } catch(FileNotFoundException e) {}
+    }
+    
+    /**
+     * Test that we can delete sheets without
+     *  breaking the build in named ranges
+     *  used for printing stuff.
+     * Currently broken, as we change the Ptg
+     */
+    public void test30978() throws Exception {
+        HSSFWorkbook wb = openSample("30978-alt.xls");
+        assertEquals(1, wb.getNumberOfNames());
+        assertEquals(3, wb.getNumberOfSheets());
+        
+        // Check all names fit within range, and use
+        //  DeletedArea3DPtg
+        Workbook w = wb.getWorkbook();
+        for(int i=0; i<w.getNumNames(); i++) {
+        	NameRecord r = w.getNameRecord(i);
+        	assertTrue(r.getIndexToSheet() <= wb.getNumberOfSheets());
+        	
+        	List nd = r.getNameDefinition();
+        	assertEquals(1, nd.size());
+        	assertTrue(nd.get(0) instanceof DeletedArea3DPtg);
+        }
+        
+        
+        // Delete the 2nd sheet
+        wb.removeSheetAt(1);
+        
+        
+        // Re-check
+        assertEquals(1, wb.getNumberOfNames());
+        assertEquals(2, wb.getNumberOfSheets());
+        
+        for(int i=0; i<w.getNumNames(); i++) {
+        	NameRecord r = w.getNameRecord(i);
+        	assertTrue(r.getIndexToSheet() <= wb.getNumberOfSheets());
+        	
+        	List nd = r.getNameDefinition();
+        	assertEquals(1, nd.size());
+        	assertTrue(nd.get(0) instanceof DeletedArea3DPtg);
+        }
+        
+        
+        // Save and re-load
+        wb = writeOutAndReadBack(wb);
+        w = wb.getWorkbook();
+        
+        assertEquals(1, wb.getNumberOfNames());
+        assertEquals(2, wb.getNumberOfSheets());
+        
+        for(int i=0; i<w.getNumNames(); i++) {
+        	NameRecord r = w.getNameRecord(i);
+        	assertTrue(r.getIndexToSheet() <= wb.getNumberOfSheets());
+        	
+        	List nd = r.getNameDefinition();
+        	assertEquals(1, nd.size());
+        	assertTrue(nd.get(0) instanceof DeletedArea3DPtg);
+        }
+    }
 }

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java Sat Jun 21 05:03:44 2008
@@ -58,6 +58,30 @@
         }
     }
     
+    public void testSetValues() throws Exception {
+        HSSFWorkbook book = new HSSFWorkbook();
+        HSSFSheet sheet = book.createSheet("test");
+        HSSFRow row = sheet.createRow(0);
+
+        HSSFCell cell = row.createCell((short)0);
+        
+        cell.setCellValue(1.2);
+        assertEquals(1.2, cell.getNumericCellValue(), 0.0001);
+        assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cell.getCellType());
+        
+        cell.setCellValue(false);
+        assertEquals(false, cell.getBooleanCellValue());
+        assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, cell.getCellType());
+        
+        cell.setCellValue(new HSSFRichTextString("Foo"));
+        assertEquals("Foo", cell.getRichStringCellValue().getString());
+        assertEquals(HSSFCell.CELL_TYPE_STRING, cell.getCellType());
+        
+        cell.setCellValue(new HSSFRichTextString("345"));
+        assertEquals("345", cell.getRichStringCellValue().getString());
+        assertEquals(HSSFCell.CELL_TYPE_STRING, cell.getCellType());
+    }
+    
     /**
      * test that Boolean and Error types (BoolErrRecord) are supported properly.
      */

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java Sat Jun 21 05:03:44 2008
@@ -257,18 +257,29 @@
                 // (who knows what they mean though...)
                 "[$-F800]dddd\\,\\ mmm\\ dd\\,\\ yyyy",
                 "[$-F900]ddd/mm/yyy",
+                // These ones specify colours, who knew that was allowed?
+                "[BLACK]dddd/mm/yy",
+                "[yeLLow]yyyy-mm-dd"
         };
         for(int i=0; i<formats.length; i++) {
-            assertTrue( HSSFDateUtil.isADateFormat(formatId, formats[i]) );
+            assertTrue(
+            		formats[i] + " is a date format", 
+            		HSSFDateUtil.isADateFormat(formatId, formats[i])
+            );
         }
         
         // Then time based ones too
         formats = new String[] {
                 "yyyy-mm-dd hh:mm:ss", "yyyy/mm/dd HH:MM:SS", 
                 "mm/dd HH:MM", "yy/mmm/dd SS",
+                "mm/dd HH:MM AM", "mm/dd HH:MM am",
+                "mm/dd HH:MM PM", "mm/dd HH:MM pm" 
         };
         for(int i=0; i<formats.length; i++) {
-            assertTrue( HSSFDateUtil.isADateFormat(formatId, formats[i]) );
+            assertTrue(
+            		formats[i] + " is a datetime format", 
+            		HSSFDateUtil.isADateFormat(formatId, formats[i])
+            );
         }
         
         // Then invalid ones
@@ -276,10 +287,14 @@
                 "yyyy*mm*dd", 
                 "0.0", "0.000",
                 "0%", "0.0%",
+                "[]Foo", "[BLACK]0.00%",
                 "", null
         };
         for(int i=0; i<formats.length; i++) {
-            assertFalse( HSSFDateUtil.isADateFormat(formatId, formats[i]) );
+            assertFalse( 
+            		formats[i] + " is not a date or datetime format",
+            		HSSFDateUtil.isADateFormat(formatId, formats[i])
+            );
         }
         
         // And these are ones we probably shouldn't allow,

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java Sat Jun 21 05:03:44 2008
@@ -20,6 +20,7 @@
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.usermodel.HSSFRow.MissingCellPolicy;
 
 /**
  * Test HSSFRow is okay.
@@ -204,4 +205,76 @@
         row.createCell((short) 255);
         assertEquals(256, row.getLastCellNum());
     }
+    
+    /**
+     * Tests for the missing/blank cell policy stuff
+     */
+    public void testGetCellPolicy() throws Exception {
+        HSSFWorkbook book = new HSSFWorkbook();
+        HSSFSheet sheet = book.createSheet("test");
+        HSSFRow row = sheet.createRow(0);
+
+        // 0 -> string
+        // 1 -> num
+        // 2 missing
+        // 3 missing
+        // 4 -> blank
+        // 5 -> num
+        row.createCell((short)0).setCellValue(new HSSFRichTextString("test"));
+        row.createCell((short)1).setCellValue(3.2);
+        row.createCell((short)4, HSSFCell.CELL_TYPE_BLANK);
+        row.createCell((short)5).setCellValue(4);
+        
+        // First up, no policy given, uses default
+        assertEquals(HSSFCell.CELL_TYPE_STRING,  row.getCell(0).getCellType());
+        assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1).getCellType());
+        assertEquals(null, row.getCell(2));
+        assertEquals(null, row.getCell(3));
+        assertEquals(HSSFCell.CELL_TYPE_BLANK,   row.getCell(4).getCellType());
+        assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(5).getCellType());
+        
+        // RETURN_NULL_AND_BLANK - same as default
+        assertEquals(HSSFCell.CELL_TYPE_STRING,  row.getCell(0, HSSFRow.RETURN_NULL_AND_BLANK).getCellType());
+        assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1, HSSFRow.RETURN_NULL_AND_BLANK).getCellType());
+        assertEquals(null, row.getCell(2, HSSFRow.RETURN_NULL_AND_BLANK));
+        assertEquals(null, row.getCell(3, HSSFRow.RETURN_NULL_AND_BLANK));
+        assertEquals(HSSFCell.CELL_TYPE_BLANK,   row.getCell(4, HSSFRow.RETURN_NULL_AND_BLANK).getCellType());
+        assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(5, HSSFRow.RETURN_NULL_AND_BLANK).getCellType());
+        
+        // RETURN_BLANK_AS_NULL - nearly the same
+        assertEquals(HSSFCell.CELL_TYPE_STRING,  row.getCell(0, HSSFRow.RETURN_BLANK_AS_NULL).getCellType());
+        assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1, HSSFRow.RETURN_BLANK_AS_NULL).getCellType());
+        assertEquals(null, row.getCell(2, HSSFRow.RETURN_BLANK_AS_NULL));
+        assertEquals(null, row.getCell(3, HSSFRow.RETURN_BLANK_AS_NULL));
+        assertEquals(null, row.getCell(4, HSSFRow.RETURN_BLANK_AS_NULL));
+        assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(5, HSSFRow.RETURN_BLANK_AS_NULL).getCellType());
+        
+        // CREATE_NULL_AS_BLANK - creates as needed
+        assertEquals(HSSFCell.CELL_TYPE_STRING,  row.getCell(0, HSSFRow.CREATE_NULL_AS_BLANK).getCellType());
+        assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1, HSSFRow.CREATE_NULL_AS_BLANK).getCellType());
+        assertEquals(HSSFCell.CELL_TYPE_BLANK,   row.getCell(2, HSSFRow.CREATE_NULL_AS_BLANK).getCellType());
+        assertEquals(HSSFCell.CELL_TYPE_BLANK,   row.getCell(3, HSSFRow.CREATE_NULL_AS_BLANK).getCellType());
+        assertEquals(HSSFCell.CELL_TYPE_BLANK,   row.getCell(4, HSSFRow.CREATE_NULL_AS_BLANK).getCellType());
+        assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(5, HSSFRow.CREATE_NULL_AS_BLANK).getCellType());
+        
+        // Check created ones get the right column
+        assertEquals((short)0, row.getCell(0, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum());
+        assertEquals((short)1, row.getCell(1, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum());
+        assertEquals((short)2, row.getCell(2, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum());
+        assertEquals((short)3, row.getCell(3, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum());
+        assertEquals((short)4, row.getCell(4, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum());
+        assertEquals((short)5, row.getCell(5, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum());
+        
+        
+        // Now change the cell policy on the workbook, check
+        //  that that is now used if no policy given
+        book.setMissingCellPolicy(HSSFRow.RETURN_BLANK_AS_NULL);
+        
+        assertEquals(HSSFCell.CELL_TYPE_STRING,  row.getCell(0).getCellType());
+        assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1).getCellType());
+        assertEquals(null, row.getCell(2));
+        assertEquals(null, row.getCell(3));
+        assertEquals(null, row.getCell(4));
+        assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(5).getCellType());
+    }
 }

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java Sat Jun 21 05:03:44 2008
@@ -36,7 +36,6 @@
 import org.apache.poi.hssf.record.WSBoolRecord;
 import org.apache.poi.hssf.record.WindowTwoRecord;
 import org.apache.poi.hssf.util.Region;
-import org.apache.poi.util.TempFile;
 
 /**
  * Tests HSSFSheet.  This test case is very incomplete at the moment.
@@ -54,10 +53,7 @@
 	/**
 	 * Test the gridset field gets set as expected.
 	 */
-
-	public void testBackupRecord()
-			throws Exception
-	{
+	public void testBackupRecord() {
 		HSSFWorkbook wb = new HSSFWorkbook();
 		HSSFSheet s = wb.createSheet();
 		Sheet sheet = s.getSheet();
@@ -70,10 +66,7 @@
 	/**
 	 * Test vertically centered output.
 	 */
-
-	public void testVerticallyCenter()
-			throws Exception
-	{
+	public void testVerticallyCenter() {
 		HSSFWorkbook wb = new HSSFWorkbook();
 		HSSFSheet s = wb.createSheet();
 		Sheet sheet = s.getSheet();
@@ -90,10 +83,7 @@
 	/**
 	 * Test horizontally centered output.
 	 */
-
-	public void testHorizontallyCenter()
-			throws Exception
-	{
+	public void testHorizontallyCenter() {
 		HSSFWorkbook wb = new HSSFWorkbook();
 		HSSFSheet s = wb.createSheet();
 		Sheet sheet = s.getSheet();
@@ -103,16 +93,13 @@
 		assertEquals(false, record.getHCenter());
 		s.setHorizontallyCenter(true);
 		assertEquals(true, record.getHCenter());
-
 	}
 
 
 	/**
 	 * Test WSBboolRecord fields get set in the user model.
 	 */
-
-	public void testWSBool()
-	{
+	public void testWSBool() {
 		HSSFWorkbook wb = new HSSFWorkbook();
 		HSSFSheet s = wb.createSheet();
 		Sheet sheet = s.getSheet();
@@ -158,9 +145,7 @@
 		assertEquals(true, s.getRowSumsRight());
 	}
 
-	public void testReadBooleans()
-			throws Exception
-	{
+	public void testReadBooleans() {
 		HSSFWorkbook workbook = new HSSFWorkbook();
 		HSSFSheet sheet = workbook.createSheet("Test boolean");
 		HSSFRow row = sheet.createRow((short) 2);
@@ -168,23 +153,16 @@
 		cell.setCellValue(true);
 		cell = row.createCell((short) 11);
 		cell.setCellValue(true);
-		File tempFile = TempFile.createTempFile("bool", "test.xls");
-		FileOutputStream stream = new FileOutputStream(tempFile);
-		workbook.write(stream);
-		stream.close();
+		
+		workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
 
-		FileInputStream readStream = new FileInputStream(tempFile);
-		workbook = new HSSFWorkbook(readStream);
 		sheet = workbook.getSheetAt(0);
 		row = sheet.getRow(2);
-		stream.close();
-		tempFile.delete();
 		assertNotNull(row);
 		assertEquals(2, row.getPhysicalNumberOfCells());
 	}
 
-	public void testRemoveRow()
-	{
+	public void testRemoveRow() {
 		HSSFWorkbook workbook = new HSSFWorkbook();
 		HSSFSheet sheet = workbook.createSheet("Test boolean");
 		HSSFRow row = sheet.createRow((short) 2);
@@ -197,8 +175,8 @@
 		HSSFRow row = sheet.createRow(0);
 		HSSFCell cell = row.createCell((short) 0);
 		HSSFCell cell2 = row.createCell((short) 1);
-		cell.setCellValue(new HSSFRichTextString("clone_test")); 
-		cell2.setCellFormula("sin(1)"); 
+		cell.setCellValue(new HSSFRichTextString("clone_test"));
+		cell2.setCellFormula("sin(1)");
 
 		HSSFSheet clonedSheet = workbook.cloneSheet(0);
 		HSSFRow clonedRow = clonedSheet.getRow(0);
@@ -234,7 +212,7 @@
 
 		assertNotNull(workbook.getSheet("Test Clone"));
 		assertNotNull(workbook.getSheet("Test Clone(1)"));
-		assertNotNull(workbook.getSheet("Test Clone(2)"));  
+		assertNotNull(workbook.getSheet("Test Clone(2)"));
 	}
 
 	/**
@@ -275,7 +253,7 @@
 	/**
 	 * Setting landscape and portrait stuff on existing sheets
 	 */
-	public void testPrintSetupLandscapeExisting() throws Exception {
+	public void testPrintSetupLandscapeExisting() {
 		HSSFWorkbook workbook = openSample("SimpleWithPageBreaks.xls");
 
 		assertEquals(3, workbook.getNumberOfSheets());
@@ -306,9 +284,7 @@
 		assertEquals(1, sheetLS.getPrintSetup().getCopies());
 
 		// Save and re-load, and check still there
-		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		workbook.write(baos);
-		workbook = new HSSFWorkbook(new ByteArrayInputStream(baos.toByteArray()));
+		workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
 
 		assertTrue(sheetL.getPrintSetup().getLandscape());
 		assertFalse(sheetPM.getPrintSetup().getLandscape());
@@ -318,7 +294,7 @@
 		assertEquals(1, sheetLS.getPrintSetup().getCopies());
 	}
 
-	public void testGroupRows() throws Exception {
+	public void testGroupRows() {
 		HSSFWorkbook workbook = new HSSFWorkbook();
 		HSSFSheet s = workbook.createSheet();
 		HSSFRow r1 = s.createRow(0);
@@ -342,11 +318,7 @@
 		assertEquals(0, r5.getOutlineLevel());
 
 		// Save and re-open
-		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		workbook.write(baos);
-		workbook = new HSSFWorkbook(
-				new ByteArrayInputStream(baos.toByteArray())
-		);
+		workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
 
 		s = workbook.getSheetAt(0);
 		r1 = s.getRow(0);
@@ -362,7 +334,7 @@
 		assertEquals(0, r5.getOutlineLevel());
 	}
 
-	public void testGroupRowsExisting() throws Exception {
+	public void testGroupRowsExisting() {
 		HSSFWorkbook workbook = openSample("NoGutsRecords.xls");
 
 		HSSFSheet s = workbook.getSheetAt(0);
@@ -391,11 +363,11 @@
 		assertEquals(0, r6.getOutlineLevel());
 
 		// Save and re-open
-		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		workbook.write(baos);
-		workbook = new HSSFWorkbook(
-				new ByteArrayInputStream(baos.toByteArray())
-		);
+		try {
+			workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
+		} catch (OutOfMemoryError e) {
+			throw new AssertionFailedError("Identified bug 39903");
+		}
 
 		s = workbook.getSheetAt(0);
 		r1 = s.getRow(0);
@@ -413,7 +385,7 @@
 		assertEquals(0, r6.getOutlineLevel());
 	}
 
-	public void testGetDrawings() throws Exception {
+	public void testGetDrawings() {
 		HSSFWorkbook wb1c = openSample("WithChart.xls");
 		HSSFWorkbook wb2c = openSample("WithTwoCharts.xls");
 
@@ -440,7 +412,7 @@
 		HSSFSheet hssfSheet = workbook.createSheet();
 		Sheet sheet = hssfSheet.getSheet();
 		ProtectRecord protect = sheet.getProtect();
-   
+
 		assertFalse(protect.getProtect());
 
 		// This will tell us that cloneSheet, and by extension,
@@ -454,12 +426,12 @@
 
 	public void testProtectSheet() {
 		short expected = (short)0xfef1;
-	HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFWorkbook wb = new HSSFWorkbook();
 		HSSFSheet s = wb.createSheet();
 		s.protectSheet("abcdefghij");
 		Sheet sheet = s.getSheet();
-	ProtectRecord protect = sheet.getProtect();
-	PasswordRecord pass = sheet.getPassword();
+		ProtectRecord protect = sheet.getProtect();
+		PasswordRecord pass = sheet.getPassword();
 		assertTrue("protection should be on",protect.getProtect());
 		assertTrue("object protection should be on",sheet.isProtected()[1]);
 		assertTrue("scenario protection should be on",sheet.isProtected()[2]);
@@ -467,9 +439,7 @@
 	}
 
 
-	public void testZoom()
-			throws Exception
-	{
+	public void testZoom() {
 		HSSFWorkbook wb = new HSSFWorkbook();
 		HSSFSheet sheet = wb.createSheet();
 		assertEquals(-1, sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid));
@@ -482,7 +452,6 @@
 		int sclLoc = sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid);
 		int window2Loc = sheet.getSheet().findFirstRecordLocBySid(WindowTwoRecord.sid);
 		assertTrue(sclLoc == window2Loc + 1);
-
 	}
 
 
@@ -493,7 +462,7 @@
 	public void testRemoveMerged() {
 		HSSFWorkbook wb = new HSSFWorkbook();
 		HSSFSheet sheet = wb.createSheet();
-		Region region = new Region(0, (short)0, 1, (short)1);   
+		Region region = new Region(0, (short)0, 1, (short)1);
 		sheet.addMergedRegion(region);
 		region = new Region(1, (short)0, 2, (short)1);
 		sheet.addMergedRegion(region);
@@ -522,7 +491,6 @@
 		assertTrue("there isn't more than one merged region in there", 1 <= sheet.getNumMergedRegions());
 		region = sheet.getMergedRegionAt(0);
 		assertEquals("the merged row to doesnt match the one we put in ", 4, region.getRowTo());
-
 	}
 
 	public void testShiftMerged() {
@@ -536,33 +504,25 @@
 		cell = row.createCell((short)1);
 		cell.setCellValue(new HSSFRichTextString("second row, second cell"));
 
-		Region region = new Region(1, (short)0, 1, (short)1);   
+		Region region = new Region(1, (short)0, 1, (short)1);
 		sheet.addMergedRegion(region);
 
 		sheet.shiftRows(1, 1, 1);
 
 		region = sheet.getMergedRegionAt(0);
 		assertEquals("Merged region not moved over to row 2", 2, region.getRowFrom());
-
 	}
 
 	/**
 	 * Tests the display of gridlines, formulas, and rowcolheadings.
 	 * @author Shawn Laubach (slaubach at apache dot org)
 	 */
-	public void testDisplayOptions() throws Exception {
+	public void testDisplayOptions() {
 		HSSFWorkbook wb = new HSSFWorkbook();
 		HSSFSheet sheet = wb.createSheet();
 
-		File tempFile = TempFile.createTempFile("display", "test.xls");
-		FileOutputStream stream = new FileOutputStream(tempFile);
-		wb.write(stream);
-		stream.close();
-
-		FileInputStream readStream = new FileInputStream(tempFile);
-		wb = new HSSFWorkbook(readStream);
+		wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
 		sheet = wb.getSheetAt(0);
-		readStream.close();
 
 		assertEquals(sheet.isDisplayGridlines(), true);
 		assertEquals(sheet.isDisplayRowColHeadings(), true);
@@ -572,16 +532,8 @@
 		sheet.setDisplayRowColHeadings(false);
 		sheet.setDisplayFormulas(true);
 
-		tempFile = TempFile.createTempFile("display", "test.xls");
-		stream = new FileOutputStream(tempFile);
-		wb.write(stream);
-		stream.close();
-
-		readStream = new FileInputStream(tempFile);
-		wb = new HSSFWorkbook(readStream);
+		wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
 		sheet = wb.getSheetAt(0);
-		readStream.close();
-
 
 		assertEquals(sheet.isDisplayGridlines(), false);
 		assertEquals(sheet.isDisplayRowColHeadings(), false);
@@ -593,7 +545,7 @@
 	 * Make sure the excel file loads work
 	 *
 	 */
-	public void testPageBreakFiles() throws Exception{
+	public void testPageBreakFiles() {
 		HSSFWorkbook wb = openSample("SimpleWithPageBreaks.xls");
 
 		HSSFSheet sheet = wb.getSheetAt(0);
@@ -611,27 +563,19 @@
 		assertEquals("row breaks number", 2, sheet.getRowBreaks().length);
 		assertEquals("column breaks number", 2, sheet.getColumnBreaks().length);
 
-		File tempFile = TempFile.createTempFile("display", "testPagebreaks.xls");
-		FileOutputStream stream = new FileOutputStream(tempFile);
-		wb.write(stream);
-		stream.close();
-
-		wb = new HSSFWorkbook(new FileInputStream(tempFile));
+		wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
 		sheet = wb.getSheetAt(0);
 
 		assertTrue("No row page break", sheet.isRowBroken(22));
 		assertTrue("No column page break", sheet.isColumnBroken((short)4));
 
-
 		assertEquals("row breaks number", 2, sheet.getRowBreaks().length);
 		assertEquals("column breaks number", 2, sheet.getColumnBreaks().length);
-
-
 	}
 
-	public void testDBCSName () throws Exception {
+	public void testDBCSName () {
 		HSSFWorkbook wb = openSample("DBCSSheetName.xls");
-		HSSFSheet s= wb.getSheetAt(1);
+		wb.getSheetAt(1);
 		assertEquals ("DBCS Sheet Name 2", wb.getSheetName(1),"\u090f\u0915" );
 		assertEquals("DBCS Sheet Name 1", wb.getSheetName(0),"\u091c\u093e");
 	}
@@ -684,17 +628,15 @@
 	/**
 	 *
 	 */
-	public void testAddEmptyRow() throws Exception {
+	public void testAddEmptyRow() {
 		//try to add 5 empty rows to a new sheet
 		HSSFWorkbook workbook = new HSSFWorkbook();
 		HSSFSheet sheet = workbook.createSheet();
-		for (int i = 0; i < 5; i++) sheet.createRow(i);
-
-		ByteArrayOutputStream out = new ByteArrayOutputStream();
-		workbook.write(out);
-		out.close();
+		for (int i = 0; i < 5; i++) {
+			sheet.createRow(i);
+		}
 
-		workbook = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+		workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
 
 		//try adding empty rows in an existing worksheet
 		workbook = openSample("Simple.xls");
@@ -702,14 +644,10 @@
 		sheet = workbook.getSheetAt(0);
 		for (int i = 3; i < 10; i++) sheet.createRow(i);
 
-		out = new ByteArrayOutputStream();
-		workbook.write(out);
-		out.close();
-
-		workbook = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+		workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
 	}
 
-	public void testAutoSizeColumn() throws Exception {
+	public void testAutoSizeColumn() {
 		HSSFWorkbook wb = openSample("43902.xls");
 		String sheetName = "my sheet";
 		HSSFSheet sheet = wb.getSheet(sheetName);
@@ -719,7 +657,7 @@
 		//  machines based on the fonts available.
 		// So, we use ranges, which are pretty large, but
 		//  thankfully don't overlap!
-		int minWithRow1And2 = 6400; 
+		int minWithRow1And2 = 6400;
 		int maxWithRow1And2 = 7800;
 		int minWithRow1Only = 2750;
 		int maxWithRow1Only = 3300;
@@ -733,13 +671,10 @@
 		//create a region over the 2nd row and auto size the first column
 		sheet.addMergedRegion(new Region(1,(short)0,1,(short)1));
 		sheet.autoSizeColumn((short)0);
-		ByteArrayOutputStream out = new ByteArrayOutputStream();
-		wb.write(out);
-		out.close();
+		HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb);
 
-		// check that the autoSized column width has ignored the 2nd row 
+		// check that the autoSized column width has ignored the 2nd row
 		// because it is included in a merged region (Excel like behavior)
-		HSSFWorkbook wb2 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
 		HSSFSheet sheet2 = wb2.getSheet(sheetName);
 		assertTrue(sheet2.getColumnWidth((short)0) >= minWithRow1Only);
 		assertTrue(sheet2.getColumnWidth((short)0) <= maxWithRow1Only);
@@ -747,10 +682,7 @@
 		// remove the 2nd row merged region and check that the 2nd row value is used to the autoSizeColumn width
 		sheet2.removeMergedRegion(1);
 		sheet2.autoSizeColumn((short)0);
-		out = new ByteArrayOutputStream();
-		wb2.write(out);
-		out.close();
-		HSSFWorkbook wb3 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+		HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
 		HSSFSheet sheet3 = wb3.getSheet(sheetName);
 		assertTrue(sheet3.getColumnWidth((short)0) >= minWithRow1And2);
 		assertTrue(sheet3.getColumnWidth((short)0) <= maxWithRow1And2);
@@ -827,7 +759,7 @@
 		assertTrue(wb3.getSheetAt(3).getForceFormulaRecalculation());
 	}
 
-	public void testColumnWidth() throws Exception {
+	public void testColumnWidth() {
 		//check we can correctly read column widths from a reference workbook
 		HSSFWorkbook wb = openSample("colwidth.xls");
 
@@ -867,11 +799,8 @@
 		}
 
 		//serialize and read again
-		ByteArrayOutputStream out = new ByteArrayOutputStream();
-		wb.write(out);
-		out.close();
+		wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
 
-		wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
 		sh = wb.getSheetAt(0);
 		assertEquals(10, sh.getDefaultColumnWidth());
 		//columns A-C have default width

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java Sat Jun 21 05:03:44 2008
@@ -20,12 +20,17 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.util.List;
 
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.model.Sheet;
 import org.apache.poi.hssf.record.NameRecord;
+import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.hssf.record.formula.Area3DPtg;
 import org.apache.poi.util.TempFile;
 /**
  *
@@ -376,4 +381,135 @@
         assertEquals("active", expectedActive, sheet.isActive());
         assertEquals("selected", expectedSelected, sheet.isSelected());
     }
-}
+    
+    /**
+     * If Sheet.getSize() returns a different result to Sheet.serialize(), this will cause the BOF
+     * records to be written with invalid offset indexes.  Excel does not like this, and such 
+     * errors are particularly hard to track down.  This test ensures that HSSFWorkbook throws
+     * a specific exception as soon as the situation is detected. See bugzilla 45066
+     */
+    public void testSheetSerializeSizeMismatch_bug45066() {
+        HSSFWorkbook wb = new HSSFWorkbook();
+        Sheet sheet = wb.createSheet("Sheet1").getSheet();
+        List sheetRecords = sheet.getRecords();
+        // one way (of many) to cause the discrepancy is with a badly behaved record:
+        sheetRecords.add(new BadlyBehavedRecord());
+        // There is also much logic inside Sheet that (if buggy) might also cause the discrepancy
+        try {
+            wb.getBytes();
+            throw new AssertionFailedError("Identified bug 45066 a");
+        } catch (IllegalStateException e) {
+            // Expected badly behaved sheet record to cause exception
+            assertTrue(e.getMessage().startsWith("Actual serialized sheet size"));
+        }
+    }
+    
+    /**
+     * Checks that us and HSSFName play nicely with named ranges
+     *  that point to deleted sheets
+     */
+    public void testNamesToDeleteSheets() throws Exception {
+    	HSSFWorkbook b = openSample("30978-deleted.xls");
+    	assertEquals(3, b.getNumberOfNames());
+    	
+    	// Sheet 2 is deleted
+    	assertEquals("Sheet1", b.getSheetName(0));
+    	assertEquals("Sheet3", b.getSheetName(1));
+    	
+    	Area3DPtg ptg;
+    	NameRecord nr;
+    	HSSFName n;
+    	
+    	/* ======= Name pointing to deleted sheet ====== */
+    	
+    	// First at low level
+    	nr = b.getWorkbook().getNameRecord(0);
+    	assertEquals("On2", nr.getNameText());
+    	assertEquals(0, nr.getIndexToSheet());
+    	assertEquals(1, nr.getExternSheetNumber());
+    	assertEquals(1, nr.getNameDefinition().size());
+    	
+    	ptg = (Area3DPtg)nr.getNameDefinition().get(0);
+    	assertEquals(1, ptg.getExternSheetIndex());
+    	assertEquals(0, ptg.getFirstColumn());
+    	assertEquals(0, ptg.getFirstRow());
+    	assertEquals(0, ptg.getLastColumn());
+    	assertEquals(2, ptg.getLastRow());
+    	
+    	// Now at high level
+    	n = b.getNameAt(0);
+    	assertEquals("On2", n.getNameName());
+    	assertEquals("", n.getSheetName());
+    	assertEquals("#REF!$A$1:$A$3", n.getReference());
+    	
+    	
+    	/* ======= Name pointing to 1st sheet ====== */
+    	
+    	// First at low level
+    	nr = b.getWorkbook().getNameRecord(1);
+    	assertEquals("OnOne", nr.getNameText());
+    	assertEquals(0, nr.getIndexToSheet());
+    	assertEquals(0, nr.getExternSheetNumber());
+    	assertEquals(1, nr.getNameDefinition().size());
+    	
+    	ptg = (Area3DPtg)nr.getNameDefinition().get(0);
+    	assertEquals(0, ptg.getExternSheetIndex());
+    	assertEquals(0, ptg.getFirstColumn());
+    	assertEquals(2, ptg.getFirstRow());
+    	assertEquals(0, ptg.getLastColumn());
+    	assertEquals(3, ptg.getLastRow());
+    	
+    	// Now at high level
+    	n = b.getNameAt(1);
+    	assertEquals("OnOne", n.getNameName());
+    	assertEquals("Sheet1", n.getSheetName());
+    	assertEquals("Sheet1!$A$3:$A$4", n.getReference());
+    	
+    	
+    	/* ======= Name pointing to 3rd sheet ====== */
+    	
+    	// First at low level
+    	nr = b.getWorkbook().getNameRecord(2);
+    	assertEquals("OnSheet3", nr.getNameText());
+    	assertEquals(0, nr.getIndexToSheet());
+    	assertEquals(2, nr.getExternSheetNumber());
+    	assertEquals(1, nr.getNameDefinition().size());
+    	
+    	ptg = (Area3DPtg)nr.getNameDefinition().get(0);
+    	assertEquals(2, ptg.getExternSheetIndex());
+    	assertEquals(0, ptg.getFirstColumn());
+    	assertEquals(0, ptg.getFirstRow());
+    	assertEquals(0, ptg.getLastColumn());
+    	assertEquals(1, ptg.getLastRow());
+    	
+    	// Now at high level
+    	n = b.getNameAt(2);
+    	assertEquals("OnSheet3", n.getNameName());
+    	assertEquals("Sheet3", n.getSheetName());
+    	assertEquals("Sheet3!$A$1:$A$2", n.getReference());
+    }
+    
+    /**
+     * result returned by getRecordSize() differs from result returned by serialize()
+     */
+    private static final class BadlyBehavedRecord extends Record {
+        public BadlyBehavedRecord() {
+            // 
+        }
+        protected void fillFields(RecordInputStream in) {
+            throw new RuntimeException("Should not be called");
+        }
+        public short getSid() {
+            return 0x777;
+        }
+        public int serialize(int offset, byte[] data) {
+            return 4;
+        }
+        protected void validateSid(short id) {
+            throw new RuntimeException("Should not be called");
+        }
+        public int getRecordSize() {
+            return 8;
+        }
+    }
+ }

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java Sat Jun 21 05:03:44 2008
@@ -17,19 +17,11 @@
 
 package org.apache.poi.hssf.usermodel;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.util.AreaReference;
 import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.util.TempFile;
 
 /**
  * 
@@ -49,9 +41,7 @@
 	}
 
 	/** Test of TestCase method, of class test.RangeTest. */
-	public void testNamedRange() 
-		throws IOException
-	{
+	public void testNamedRange() {
 		HSSFWorkbook wb = openSample("Simple.xls");
 
 		//Creating new Named Range
@@ -64,7 +54,7 @@
 		newNamedRange.setNameName("RangeTest");
 		//Setting its reference
 		newNamedRange.setReference(sheetName + "!$D$4:$E$8");
-  
+
 		//Getting NAmed Range
 		HSSFName namedRange1 = wb.getNameAt(0);
 		//Getting it sheet name
@@ -76,22 +66,10 @@
 		SanityChecker c = new SanityChecker();
 		c.checkHSSFWorkbook(wb);
 
-		File file = TempFile.createTempFile("testNamedRange", ".xls");
-
-		FileOutputStream fileOut = new FileOutputStream(file);
-		wb.write(fileOut);
-
-		fileOut.close();
-
-		assertTrue("file exists",file.exists());
-
-		FileInputStream in = new FileInputStream(file);
-		wb = new HSSFWorkbook(in);
+		wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
 		HSSFName nm =wb.getNameAt(wb.getNameIndex("RangeTest"));
 		assertTrue("Name is "+nm.getNameName(),"RangeTest".equals(nm.getNameName()));
 		assertEquals(wb.getSheetName(0)+"!$D$4:$E$8", nm.getReference());
-
-
 	}
 	 
 	/**
@@ -143,13 +121,11 @@
 	/**
 	 * Test that multiple named ranges can be added written and read
 	 */
-	public void testMultipleNamedWrite() 
-		throws IOException
-	{
+	public void testMultipleNamedWrite() {
 		HSSFWorkbook wb	 = new HSSFWorkbook();
 		 
 
-		HSSFSheet sheet = wb.createSheet("testSheet1");
+		wb.createSheet("testSheet1");
 		String sheetName = wb.getSheetName(0);
 
 		assertEquals("testSheet1", sheetName);
@@ -170,18 +146,7 @@
 		HSSFName namedRange1 = wb.getNameAt(0);
 		String referece = namedRange1.getReference();
 
-		File file = TempFile.createTempFile("testMultiNamedRange", ".xls");
- 
-		FileOutputStream fileOut = new FileOutputStream(file);
-		wb.write(fileOut);
-		fileOut.close();
-
-		 
-		assertTrue("file exists",file.exists());
-
-
-		FileInputStream in = new FileInputStream(file);
-		wb = new HSSFWorkbook(in);
+		wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
 		HSSFName nm =wb.getNameAt(wb.getNameIndex("RangeTest"));
 		assertTrue("Name is "+nm.getNameName(),"RangeTest".equals(nm.getNameName()));
 		assertTrue("Reference is "+nm.getReference(),(wb.getSheetName(0)+"!$D$4:$E$8").equals(nm.getReference()));
@@ -189,19 +154,14 @@
 		nm = wb.getNameAt(wb.getNameIndex("AnotherTest"));
 		assertTrue("Name is "+nm.getNameName(),"AnotherTest".equals(nm.getNameName()));
 		assertTrue("Reference is "+nm.getReference(),newNamedRange2.getReference().equals(nm.getReference()));
-
-
 	}
 
 	/**
 	 * Test case provided by czhang@cambian.com (Chun Zhang)
 	 * <p>
 	 * Addresses Bug <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=13775" target="_bug">#13775</a>
-	 * @throws IOException
 	 */
-	public void testMultiNamedRange() 
-		 throws IOException
-	 {
+	public void testMultiNamedRange() {
 
 		 // Create a new workbook
 		 HSSFWorkbook wb = new HSSFWorkbook ();
@@ -234,16 +194,8 @@
 		 namedRange2.setReference("sheet2" + "!$A$1:$O$21");
  
 		 // Write the workbook to a file
-		 File file = TempFile.createTempFile("testMuiltipletNamedRanges", ".xls");
-		 FileOutputStream fileOut = new FileOutputStream(file);
-		 wb.write(fileOut);
-		 fileOut.close();
-
-		 assertTrue("file exists",file.exists());
-
 		 // Read the Excel file and verify its content
-		 FileInputStream in = new FileInputStream(file);
-		 wb = new HSSFWorkbook(in);
+		 wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
 		 HSSFName nm1 =wb.getNameAt(wb.getNameIndex("RangeTest1"));
 		 assertTrue("Name is "+nm1.getNameName(),"RangeTest1".equals(nm1.getNameName()));
 		 assertTrue("Reference is "+nm1.getReference(),(wb.getSheetName(0)+"!$A$1:$L$41").equals(nm1.getReference()));
@@ -253,17 +205,15 @@
 		 assertTrue("Reference is "+nm2.getReference(),(wb.getSheetName(1)+"!$A$1:$O$21").equals(nm2.getReference()));
 	 }	   
 
-	public void testUnicodeNamedRange() throws Exception {
+	public void testUnicodeNamedRange() {
 		HSSFWorkbook workBook = new HSSFWorkbook();
-		HSSFSheet sheet = workBook.createSheet("Test");
+		workBook.createSheet("Test");
 		HSSFName name = workBook.createName();
 		name.setNameName("\u03B1");
 		name.setReference("Test!$D$3:$E$8");
 
-		ByteArrayOutputStream out = new ByteArrayOutputStream();
-		workBook.write(out);
 
-		HSSFWorkbook workBook2 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+		HSSFWorkbook workBook2 = HSSFTestDataSamples.writeOutAndReadBack(workBook);
 		HSSFName name2 = workBook2.getNameAt(0);
 
 		assertEquals("\u03B1", name2.getNameName());
@@ -286,7 +236,6 @@
 
 	 	 assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
 		 assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
-		 
 	 }
 
 	 /**
@@ -305,10 +254,8 @@
 
 		 assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
 		 assertEquals("'" + sheetName + "'!" + reference, retrievedPrintArea);
-		 
 	 }
 
-
 	 /**
 	  * Test to see if the print area can be retrieved from an excel created file
 	  */
@@ -321,88 +268,71 @@
 		assertEquals(reference, workbook.getPrintArea(0));
 	}
 
-
 	 /**
 	  * Test to see if the print area made it to the file
 	  */
-	 public void testPrintAreaFile()
-	 throws IOException
-	 {
+	 public void testPrintAreaFile() {
 	 	HSSFWorkbook workbook = new HSSFWorkbook();
-	 	HSSFSheet sheet = workbook.createSheet("Test Print Area");
+	 	workbook.createSheet("Test Print Area");
 	 	String sheetName = workbook.getSheetName(0);
 		 
 	 
 	 	String reference = sheetName+"!$A$1:$B$1";
 	 	workbook.setPrintArea(0, reference);
 		 
-		File file = TempFile.createTempFile("testPrintArea",".xls");
-		 
-		FileOutputStream fileOut = new FileOutputStream(file);
-		workbook.write(fileOut);
-		fileOut.close();
-		 
-		assertTrue("file exists",file.exists());
-		 
-		FileInputStream in = new FileInputStream(file);
-		workbook = new HSSFWorkbook(in);
+		workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
 		 
 	 	String retrievedPrintArea = workbook.getPrintArea(0);	   
 	 	assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
 	 	assertEquals("References Match", "'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
-		 
 	}
 
 	/**
 	 * Test to see if multiple print areas made it to the file
 	 */
-	public void testMultiplePrintAreaFile()
-	throws IOException
-	{
+	public void testMultiplePrintAreaFile() {
 		HSSFWorkbook workbook = new HSSFWorkbook();
 
-		HSSFSheet sheet = workbook.createSheet("Sheet1");
-		sheet = workbook.createSheet("Sheet2");
-		sheet = workbook.createSheet("Sheet3");
-
-		String sheetName = workbook.getSheetName(0);
-		String reference = null;
-
-		reference = sheetName+"!$A$1:$B$1";
-		workbook.setPrintArea(0, reference); 
-
-		sheetName = workbook.getSheetName(1);
-		String reference2 = sheetName+"!$B$2:$D$5";
+		workbook.createSheet("Sheet1");
+		workbook.createSheet("Sheet2");
+		workbook.createSheet("Sheet3");
+		String reference1 = "Sheet1!$A$1:$B$1";
+		String reference2 = "Sheet2!$B$2:$D$5";
+		String reference3 = "Sheet3!$D$2:$F$5";
+		
+		workbook.setPrintArea(0, reference1); 
 		workbook.setPrintArea(1, reference2);
-
-		sheetName = workbook.getSheetName(2);
-		String reference3 = sheetName+"!$D$2:$F$5";
 		workbook.setPrintArea(2, reference3);
 
-		File file = TempFile.createTempFile("testMultiPrintArea",".xls");
+		//Check created print areas
+		String retrievedPrintArea;
+		
+		retrievedPrintArea = workbook.getPrintArea(0);
+		assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea);
+		assertEquals(reference1, retrievedPrintArea);
 
-		FileOutputStream fileOut = new FileOutputStream(file);
-		workbook.write(fileOut);
-		fileOut.close();
+		retrievedPrintArea = workbook.getPrintArea(1);
+		assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea);
+		assertEquals(reference2, retrievedPrintArea);
 
-		assertTrue("file exists",file.exists());
+		retrievedPrintArea = workbook.getPrintArea(2);
+		assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea);
+		assertEquals(reference3, retrievedPrintArea);
 
-		FileInputStream in = new FileInputStream(file);
-		workbook = new HSSFWorkbook(in);
+		// Check print areas after re-reading workbook
+		workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
 
-		String retrievedPrintArea = workbook.getPrintArea(0);
+		retrievedPrintArea = workbook.getPrintArea(0);
 		assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea);
-		assertEquals(reference, retrievedPrintArea);
-
-		String retrievedPrintArea2 = workbook.getPrintArea(1);
-		assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea2);
-		assertEquals(reference2, retrievedPrintArea2);
-
-		String retrievedPrintArea3 = workbook.getPrintArea(2);
-		assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea3);
-		assertEquals(reference3, retrievedPrintArea3);
-
+		assertEquals(reference1, retrievedPrintArea);
 
+		retrievedPrintArea = workbook.getPrintArea(1);
+		assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea);
+		assertEquals(reference2, retrievedPrintArea);
+
+		retrievedPrintArea = workbook.getPrintArea(2);
+		assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea);
+		assertEquals(reference3, retrievedPrintArea);
 	}
 
 	/**
@@ -530,31 +460,29 @@
 		HSSFSheet s = wb.getSheet(cref.getSheetName());
 		HSSFRow r = sheet.getRow(cref.getRow());
 		HSSFCell c = r.getCell(cref.getCol());
-		String contents = c.getStringCellValue();
+		String contents = c.getRichStringCellValue().getString();
 		assertEquals("Contents of cell retrieved by its named reference", contents, cvalue);
 	}
 
-    public void testDeletedReference() throws Exception {
-        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("24207.xls");
-        assertEquals(2, wb.getNumberOfNames());
-
-        HSSFName name1 = wb.getNameAt(0);
-        assertEquals("a", name1.getNameName());
-        assertEquals("Sheet1!$A$1", name1.getReference());
-        AreaReference ref1 = new AreaReference(name1.getReference());
-        assertTrue("Successfully constructed first reference", true);
-
-        HSSFName name2 = wb.getNameAt(1);
-        assertEquals("b", name2.getNameName());
-        assertEquals("#REF!", name2.getReference());
-        assertTrue(name2.isDeleted());
-        try {
-            AreaReference ref2 = new AreaReference(name2.getReference());
-            fail("attempt to supply an invalid reference to AreaReference constructor results in exception");
-        } catch (Exception e){
-            ;
-        }
-
-    }
-
+	public void testDeletedReference() throws Exception {
+		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("24207.xls");
+		assertEquals(2, wb.getNumberOfNames());
+
+		HSSFName name1 = wb.getNameAt(0);
+		assertEquals("a", name1.getNameName());
+		assertEquals("Sheet1!$A$1", name1.getReference());
+		AreaReference ref1 = new AreaReference(name1.getReference());
+		assertTrue("Successfully constructed first reference", true);
+
+		HSSFName name2 = wb.getNameAt(1);
+		assertEquals("b", name2.getNameName());
+		assertEquals("#REF!", name2.getReference());
+		assertTrue(name2.isDeleted());
+		try {
+			AreaReference ref2 = new AreaReference(name2.getReference());
+			fail("attempt to supply an invalid reference to AreaReference constructor results in exception");
+		} catch (StringIndexOutOfBoundsException e) { // TODO - use a different exception for this condition
+			// expected during successful test
+		}
+   }
 }

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java Sat Jun 21 05:03:44 2008
@@ -45,8 +45,8 @@
 	 */
 	public void testTextSheets() throws Exception {
 		// Both should have two sheets
-		assertEquals(2, wbH.sheets.size());
-		assertEquals(2, wbU.sheets.size());
+		assertEquals(2, wbH.getNumberOfSheets());
+		assertEquals(2, wbU.getNumberOfSheets());
 
 		// All sheets should have one row
 		assertEquals(0, wbH.getSheetAt(0).getLastRowNum());

Modified: poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java?rev=670186&r1=670185&r2=670186&view=diff
==============================================================================
--- poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java (original)
+++ poi/tags/REL_3_1_FINAL/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java Sat Jun 21 05:03:44 2008
@@ -130,7 +130,7 @@
 	 * The other is to fix the handling of the last block in
 	 *  POIFS, since it seems to be slight wrong
 	 */
-	public void DISABLEDtestShortLastBlock() throws Exception {
+	public void testShortLastBlock() throws Exception {
 		String[] files = new String[] {
 			"ShortLastBlock.qwp", "ShortLastBlock.wps"	
 		};



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


Mime
View raw message