poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r759112 [2/3] - in /poi/trunk/src: java/org/apache/poi/hssf/record/aggregates/ java/org/apache/poi/hssf/usermodel/ ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/ ooxml/java/org/apache/poi/xssf/usermodel/ ooxml/testcases/org/apache/poi/...
Date Fri, 27 Mar 2009 11:50:53 GMT
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java Fri Mar 27 11:50:52 2009
@@ -27,6 +27,7 @@
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.xssf.model.StylesTable;
 import org.apache.poi.openxml4j.opc.ContentTypes;
 import org.apache.poi.openxml4j.opc.OPCPackage;
@@ -35,139 +36,14 @@
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
 
-public final class TestXSSFWorkbook extends TestCase {
-
-	@Override
-	protected void setUp() {
-		// Use system out logger
-		System.setProperty(
-				"org.apache.poi.util.POILogger",
-				"org.apache.poi.util.SystemOutLogger"
-		);
-	}
-
-	public void testGetSetActiveSheet(){
-		XSSFWorkbook workbook = new XSSFWorkbook();
-        assertEquals(0, workbook.getActiveSheetIndex());
-
-		workbook.createSheet("sheet1");
-		workbook.createSheet("sheet2");
-		workbook.createSheet("sheet3");
-		// set second sheet
-		workbook.setActiveSheet(1);
-		// test if second sheet is set up
-		assertEquals(1, workbook.getActiveSheetIndex());
-	}
-
-	public void testGetSheetIndex() {
-		XSSFWorkbook workbook = new XSSFWorkbook();
-		Sheet sheet1 = workbook.createSheet("sheet1");
-		Sheet sheet2 = workbook.createSheet("sheet2");
-		assertEquals(0, workbook.getSheetIndex(sheet1));
-		assertEquals(0, workbook.getSheetIndex("sheet1"));
-		assertEquals(1, workbook.getSheetIndex(sheet2));
-		assertEquals(1, workbook.getSheetIndex("sheet2"));
-		assertEquals(-1, workbook.getSheetIndex("noSheet"));
-	}
-	
-	public void testSetSheetOrder() {
-		XSSFWorkbook workbook = new XSSFWorkbook();
-		Sheet sheet1 = workbook.createSheet("sheet1");
-		Sheet sheet2 = workbook.createSheet("sheet2");
-		assertSame(sheet1, workbook.getSheetAt(0));
-		assertSame(sheet2, workbook.getSheetAt(1));
-		workbook.setSheetOrder("sheet2", 0);
-		assertSame(sheet2, workbook.getSheetAt(0));
-		assertSame(sheet1, workbook.getSheetAt(1));
-		// Test reordering of CTSheets
-		CTWorkbook ctwb = workbook.getCTWorkbook();
-		CTSheet[] ctsheets = ctwb.getSheets().getSheetArray();
-		assertEquals("sheet2", ctsheets[0].getName());
-		assertEquals("sheet1", ctsheets[1].getName());
-		
-		// Borderline case: only one sheet
-		workbook = new XSSFWorkbook();
-		sheet1 = workbook.createSheet("sheet1");
-		assertSame(sheet1, workbook.getSheetAt(0));
-		workbook.setSheetOrder("sheet1", 0);
-		assertSame(sheet1, workbook.getSheetAt(0));
-	}
-	
-	public void testSetSheetName() {
-		XSSFWorkbook workbook = new XSSFWorkbook();
-		workbook.createSheet("sheet1");
-		assertEquals("sheet1", workbook.getSheetName(0));
-		workbook.setSheetName(0, "sheet2");
-		assertEquals("sheet2", workbook.getSheetName(0));
-	}
-	
-	public void testCloneSheet() {
-        XSSFWorkbook book = new XSSFWorkbook();
-        XSSFSheet sheet = book.createSheet("TEST");
-        sheet.createRow(0).createCell(0).setCellValue("Test");
-        sheet.createRow(1).createCell(0).setCellValue(36.6);
-        sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 2));
-        sheet.addMergedRegion(new CellRangeAddress(1, 2, 0, 2));
-        assertTrue(sheet.isSelected());
-
-        XSSFSheet clonedSheet = book.cloneSheet(0);
-        assertEquals("TEST (2)", clonedSheet.getSheetName());
-        assertEquals(2, clonedSheet.getPhysicalNumberOfRows());
-        assertEquals(2, clonedSheet.getNumMergedRegions());
-        assertFalse(clonedSheet.isSelected());
-
-        //cloned sheet is a deep copy, adding rows in the original does not affect the clone
-        sheet.createRow(2).createCell(0).setCellValue(1);
-        sheet.addMergedRegion(new CellRangeAddress(0, 2, 0, 2));
-        assertEquals(2, clonedSheet.getPhysicalNumberOfRows());
-        assertEquals(2, clonedSheet.getPhysicalNumberOfRows());
-
-        clonedSheet.createRow(2).createCell(0).setCellValue(1);
-        clonedSheet.addMergedRegion(new CellRangeAddress(0, 2, 0, 2));
-        assertEquals(3, clonedSheet.getPhysicalNumberOfRows());
-        assertEquals(3, clonedSheet.getPhysicalNumberOfRows());
+public final class TestXSSFWorkbook extends BaseTestWorkbook {
 
+    @Override
+    protected XSSFITestDataProvider getTestDataProvider(){
+        return XSSFITestDataProvider.getInstance();
     }
-	
-	public void testGetSheetByName() {
-		XSSFWorkbook workbook = new XSSFWorkbook();
-		Sheet sheet1 = workbook.createSheet("sheet1");
-		Sheet sheet2 = workbook.createSheet("sheet2");
-		assertSame(sheet1, workbook.getSheet("sheet1"));
-		assertSame(sheet2, workbook.getSheet("sheet2"));
-		assertNull(workbook.getSheet("nosheet"));
-	}
-	
-	public void testRemoveSheetAt() {
-		XSSFWorkbook workbook = new XSSFWorkbook();
-		workbook.createSheet("sheet1");
-		workbook.createSheet("sheet2");
-		workbook.createSheet("sheet3");
-		workbook.removeSheetAt(1);
-		assertEquals(2, workbook.getNumberOfSheets());
-		assertEquals("sheet3", workbook.getSheetName(1));
-		workbook.removeSheetAt(0);
-		assertEquals(1, workbook.getNumberOfSheets());
-		assertEquals("sheet3", workbook.getSheetName(0));
-		workbook.removeSheetAt(0);
-		assertEquals(0, workbook.getNumberOfSheets());
-	}
-
-	public void testPrintArea(){
-	 Workbook workbook = new XSSFWorkbook();
-	 Sheet sheet = workbook.createSheet("Test Print Area");
-	 String sheetName = workbook.getSheetName(0);
-	 
-	// String reference = sheetName+"!$A$1:$B$1";
-	// workbook.setPrintArea(0, reference);
-	 workbook.setPrintArea(0,1,5,4,9);
-	 
-	 String retrievedPrintArea = workbook.getPrintArea(0);
 
- 	 //assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
-	 assertEquals("'"+sheetName+"'!$B$5:$F$10", retrievedPrintArea);
-}
-	
+
 	public void testRepeatingRowsAndColums() {
 		// First test that setting RR&C for same sheet more than once only creates a 
 		// single  Print_Titles built-in record
@@ -205,24 +81,9 @@
 		assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr2.getNameName());
 		assertEquals("'SecondSheet'!$B:$C,'SecondSheet'!$1:$1", nr2.getRefersToFormula());
 		
-		
 		nwb.setRepeatingRowsAndColumns(1, -1, -1, -1, -1);
-
 	}
 	
-
-	/**
-	 * Tests that we can save a new document
-	 */
-	public void testSaveNew() {
-		XSSFWorkbook workbook = new XSSFWorkbook();
-		workbook.createSheet("sheet1");
-		workbook.createSheet("sheet2");
-		workbook.createSheet("sheet3");
-
-        XSSFTestDataSamples.writeOutAndReadBack(workbook);
-	}
-
 	/**
 	 * Tests that we can save, and then re-load a new document
 	 */
@@ -242,8 +103,8 @@
 		assertEquals(1, workbook.getSheetAt(0).getLastRowNum());
 		assertEquals(0, workbook.getSheetAt(1).getFirstRowNum());
 		assertEquals(0, workbook.getSheetAt(1).getLastRowNum());
-		assertEquals(-1, workbook.getSheetAt(2).getFirstRowNum());
-		assertEquals(-1, workbook.getSheetAt(2).getLastRowNum());
+		assertEquals(0, workbook.getSheetAt(2).getFirstRowNum());
+		assertEquals(0, workbook.getSheetAt(2).getLastRowNum());
 		
 		File file = File.createTempFile("poi-", ".xlsx");
 		OutputStream out = new FileOutputStream(file);
@@ -278,8 +139,8 @@
 		assertEquals(1, workbook.getSheetAt(0).getLastRowNum());
 		assertEquals(0, workbook.getSheetAt(1).getFirstRowNum());
 		assertEquals(0, workbook.getSheetAt(1).getLastRowNum());
-		assertEquals(-1, workbook.getSheetAt(2).getFirstRowNum());
-		assertEquals(-1, workbook.getSheetAt(2).getLastRowNum());
+		assertEquals(0, workbook.getSheetAt(2).getFirstRowNum());
+		assertEquals(0, workbook.getSheetAt(2).getLastRowNum());
 		
 		sheet1 = workbook.getSheetAt(0);
 		assertEquals(1.2, sheet1.getRow(0).getCell(0).getNumericCellValue(), 0.0001);
@@ -379,13 +240,6 @@
 		assertNotSame(2, i);		
 	}
 	
-	public void testGetDisplayedTab(){
-		XSSFWorkbook workbook = new XSSFWorkbook();
-		short i = (short) workbook.getFirstVisibleTab();
-		//get default diplayedTab
-		assertEquals(0, i);		
-	}
-	
 	public void testSetDisplayedTab(){
 		XSSFWorkbook workbook = new XSSFWorkbook();
 		workbook.setFirstVisibleTab(1);
@@ -395,8 +249,8 @@
 		//1 is the default tab
 		assertEquals(1, i);
 	}
-	
-	
+
+
 	public void testLoadSave() {
 		XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
 		assertEquals(3, workbook.getNumberOfSheets());
@@ -458,94 +312,4 @@
 		assertEquals(1, st.getBorders().size());
 	}
 	
-	public void testNamedRanges() {
-		// First up, a new file
-		XSSFWorkbook workbook = new XSSFWorkbook();
-		assertEquals(0, workbook.getNumberOfNames());
-		
-		Name nameA = workbook.createName();
-		nameA.setRefersToFormula("A2");
-		nameA.setNameName("ForA2");
-		
-		XSSFName nameB = workbook.createName();
-		nameB.setRefersToFormula("B3");
-		nameB.setNameName("ForB3");
-		nameB.setComment("B3 Comment");
-		
-		// Save and re-load
-		workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
-		
-		assertEquals(2, workbook.getNumberOfNames());
-		assertEquals("A2", workbook.getNameAt(0).getRefersToFormula());
-		assertEquals("ForA2", workbook.getNameAt(0).getNameName());
-		assertNull(workbook.getNameAt(0).getComment());
-		
-		assertEquals("B3", workbook.getNameAt(1).getRefersToFormula());
-		assertEquals("ForB3", workbook.getNameAt(1).getNameName());
-		assertEquals("B3 Comment", workbook.getNameAt(1).getComment());
-		
-		assertEquals("ForA2", workbook.getNameAt(0).getNameName());
-		assertEquals(1, workbook.getNameIndex("ForB3"));
-		assertEquals(-1, workbook.getNameIndex("ForB3!!"));
-		
-		
-		// Now, an existing file with named ranges
-		workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx");
-
-		assertEquals(2, workbook.getNumberOfNames());
-		assertEquals("Sheet1!$A$2:$A$7", workbook.getNameAt(0).getRefersToFormula());
-		assertEquals("AllANumbers", workbook.getNameAt(0).getNameName());
-		assertEquals("All the numbers in A", workbook.getNameAt(0).getComment());
-		
-		assertEquals("Sheet1!$B$2:$B$7", workbook.getNameAt(1).getRefersToFormula());
-		assertEquals("AllBStrings", workbook.getNameAt(1).getNameName());
-		assertEquals("All the strings in B", workbook.getNameAt(1).getComment());
-		
-		// Tweak, save, and re-check
-		workbook.getNameAt(1).setNameName("BStringsFun");
-		
-		workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
-		
-		assertEquals(2, workbook.getNumberOfNames());
-		assertEquals("Sheet1!$A$2:$A$7", workbook.getNameAt(0).getRefersToFormula());
-		assertEquals("AllANumbers", workbook.getNameAt(0).getNameName());
-		assertEquals("All the numbers in A", workbook.getNameAt(0).getComment());
-		
-		assertEquals("Sheet1!$B$2:$B$7", workbook.getNameAt(1).getRefersToFormula());
-		assertEquals("BStringsFun", workbook.getNameAt(1).getNameName());
-		assertEquals("All the strings in B", workbook.getNameAt(1).getComment());
-	}
-	
-	public void testDuplicateNames() {
-
-		XSSFWorkbook wb = new XSSFWorkbook();
-		wb.createSheet("Sheet1");
-		wb.createSheet();
-		wb.createSheet("name1");
-		try {
-		wb.createSheet("name1");
-			fail();
-		} catch (IllegalArgumentException e) {
-			assertEquals("The workbook already contains a sheet of this name", e.getMessage());
-		}
-
-		wb.createSheet();
-
-		try {
-			wb.setSheetName(3, "name1");
-			fail();
-		} catch (IllegalArgumentException e) {
-			assertEquals("The workbook already contains a sheet of this name", e.getMessage());
-		}
-
-		try {
-			wb.setSheetName(3, "Sheet1");
-			fail();
-		} catch (IllegalArgumentException e) {
-			assertEquals("The workbook already contains a sheet of this name", e.getMessage());
-		}
-
-		wb.setSheetName(3, "name2");
-		wb.setSheetName(3, "Sheet3");
-	}
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java Fri Mar 27 11:50:52 2009
@@ -57,8 +57,6 @@
 		result.addTestSuite(TestHSSFRichTextString.class);
 		result.addTestSuite(TestHSSFRow.class);
 		result.addTestSuite(TestHSSFSheet.class);
-		result.addTestSuite(TestHSSFSheetOrder.class);
-		result.addTestSuite(TestHSSFSheetSetOrder.class);
 		result.addTestSuite(TestHSSFTextbox.class);
 		result.addTestSuite(TestHSSFWorkbook.class);
 		result.addTestSuite(TestLinkTable.class);

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Fri Mar 27 11:50:52 2009
@@ -625,27 +625,6 @@
     }
 
     /**
-     * Bug 40296:      HSSFCell.setCellFormula throws
-     *   ClassCastException if cell is created using HSSFRow.createCell(short column, int type)
-     */
-    public void test40296() {
-        HSSFWorkbook wb = new HSSFWorkbook();
-
-        HSSFWorkbook workBook = new HSSFWorkbook();
-        HSSFSheet workSheet = workBook.createSheet("Sheet1");
-        HSSFCell cell;
-        HSSFRow row = workSheet.createRow(0);
-        cell = row.createCell(0, HSSFCell.CELL_TYPE_NUMERIC);
-        cell.setCellValue(1.0);
-        cell = row.createCell(1, HSSFCell.CELL_TYPE_NUMERIC);
-        cell.setCellValue(2.0);
-        cell = row.createCell(2, HSSFCell.CELL_TYPE_FORMULA);
-        cell.setCellFormula("SUM(A1:B1)");
-
-        writeOutAndReadBack(wb);
-    }
-
-    /**
      * Test bug 38266: NPE when adding a row break
      *
      * User's diagnosis:

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java Fri Mar 27 11:50:52 2009
@@ -44,21 +44,6 @@
         return HSSFITestDataProvider.getInstance();
     }
 
-	public void testSetValues() {
-		baseTestSetValues();
-	}
-	
-	/**
-	 * test that Boolean and Error types (BoolErrRecord) are supported properly.
-	 */
-	public void testBoolErr() {
-        baseTestBoolErr();
-	}
-
-    public void testSetFormulaValue() {
-        baseTestSetFormulaValue();
-    }
-
 	/**
 	 * Checks that the recognition of files using 1904 date windowing
 	 *  is working properly. Conversion of the date is also an issue,
@@ -169,13 +154,6 @@
 	}
 
 	/**
-	 * test that Cell Styles being applied to formulas remain intact
-	 */
-	public void testFormulaStyle() {
-        baseTestFormulaStyle();
-	}
-
-	/**
 	 * Test reading hyperlinks
 	 */
 	public void testWithHyperlink() {
@@ -219,13 +197,8 @@
 		assertEquals(1, link2.getFirstColumn());
 	}
 	
-	/**tests the toString() method of HSSFCell*/
-	public void testToString() {
-		baseTestToString();
-	}
-	
 	public void testSetStringInFormulaCell_bug44606() {
-		HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFWorkbook wb = getTestDataProvider().createWorkbook();
 		HSSFCell cell = wb.createSheet("Sheet1").createRow(0).createCell(0);
 		cell.setCellFormula("B1&C1");
 		try {

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java Fri Mar 27 11:50:52 2009
@@ -35,7 +35,7 @@
         HSSFSheet sheet = wb.createSheet("test");
         HSSFClientAnchor a = new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short)0,0);
         float p = a.getAnchorHeightInPoints(sheet);
-        assertEquals(11.953,p,0.001);
+        assertEquals(12.7,p,0.001);
 
         sheet.createRow(0).setHeightInPoints(14);
         a = new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short)0,0);
@@ -57,7 +57,7 @@
         sheet.createRow(0).setHeightInPoints(12);
         a = new HSSFClientAnchor(0,127,1023,127,(short)0,0,(short)0,1);
         p = a.getAnchorHeightInPoints(sheet);
-        assertEquals(12.0,p,0.001);
+        assertEquals(12.372,p,0.001);
 
     }
 
@@ -96,7 +96,7 @@
             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};
+        float[] ref = {25.5f, 19.125f, 25.5f, 31.875f};
         for (int i = 0; i < anchor.length; i++) {
             float height = anchor[i].getAnchorHeightInPoints(sheet);
             assertEquals(ref[i], height, 0);

Added: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java?rev=759112&view=auto
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java (added)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java Fri Mar 27 11:50:52 2009
@@ -0,0 +1,48 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.usermodel;
+
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import junit.framework.AssertionFailedError;
+import org.apache.poi.hssf.HSSFITestDataProvider;
+import org.apache.poi.hssf.model.Sheet;
+import org.apache.poi.hssf.record.DBCellRecord;
+import org.apache.poi.hssf.record.FormulaRecord;
+import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.StringRecord;
+import org.apache.poi.ss.usermodel.ErrorConstants;
+import org.apache.poi.ss.usermodel.BaseTestCell;
+import org.apache.poi.ss.usermodel.BaseTestNamedRange;
+
+/**
+ * Tests various functionality having to do with {@link org.apache.poi.hssf.usermodel.HSSFCell}.  For instance support for
+ * particular 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 final class TestHSSFName extends BaseTestNamedRange {
+
+    @Override
+    protected HSSFITestDataProvider getTestDataProvider(){
+        return HSSFITestDataProvider.getInstance();
+    }
+
+}
\ No newline at end of file

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java Fri Mar 27 11:50:52 2009
@@ -21,36 +21,31 @@
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.HSSFITestDataProvider;
 import org.apache.poi.hssf.record.BlankRecord;
 import org.apache.poi.hssf.record.RowRecord;
+import org.apache.poi.ss.usermodel.BaseTestRow;
 
 /**
  * Test HSSFRow is okay.
  *
  * @author Glen Stampoultzis (glens at apache.org)
  */
-public final class TestHSSFRow extends TestCase {
+public final class TestHSSFRow extends BaseTestRow {
 
-    public void testLastAndFirstColumns() {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheet = workbook.createSheet();
-        HSSFRow row = sheet.createRow(0);
-        assertEquals(-1, row.getFirstCellNum());
-        assertEquals(-1, row.getLastCellNum());
-
-        row.createCell(2);
-        assertEquals(2, row.getFirstCellNum());
-        assertEquals(3, row.getLastCellNum());
+    @Override
+    protected HSSFITestDataProvider getTestDataProvider(){
+        return HSSFITestDataProvider.getInstance();
+    }
 
-        row.createCell(1);
-        assertEquals(1, row.getFirstCellNum());
-        assertEquals(3, row.getLastCellNum());
+    public void testRowBounds() {
+        baseTestRowBounds(RowRecord.MAX_ROW_NUMBER);
+    }
 
-        // check the exact case reported in 'bug' 43901 - notice that the cellNum is '0' based
-        row.createCell(3);
-        assertEquals(1, row.getFirstCellNum());
-        assertEquals(4, row.getLastCellNum());
+    public void testCellBounds() {
+        baseTestCellBounds(HSSFCell.LAST_COLUMN_NUMBER);
     }
+
     public void testLastAndFirstColumns_bug46654() {
         int ROW_IX = 10;
         int COL_IX = 3;
@@ -78,67 +73,6 @@
         assertEquals(-1, row.getLastCellNum());
     }
 
-    /**
-     * Make sure that there is no cross-talk between rows especially with getFirstCellNum and getLastCellNum
-     * This test was added in response to bug report 44987.
-     */
-    public void testBoundsInMultipleRows() {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheet = workbook.createSheet();
-        HSSFRow rowA = sheet.createRow(0);
-
-        rowA.createCell(10);
-        rowA.createCell(5);
-        assertEquals(5, rowA.getFirstCellNum());
-        assertEquals(11, rowA.getLastCellNum());
-
-        HSSFRow rowB = sheet.createRow(1);
-        rowB.createCell(15);
-        rowB.createCell(30);
-        assertEquals(15, rowB.getFirstCellNum());
-        assertEquals(31, rowB.getLastCellNum());
-
-        assertEquals(5, rowA.getFirstCellNum());
-        assertEquals(11, rowA.getLastCellNum());
-        rowA.createCell(50);
-        assertEquals(51, rowA.getLastCellNum());
-
-        assertEquals(31, rowB.getLastCellNum());
-    }
-
-    public void testRemoveCell() {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheet = workbook.createSheet();
-        HSSFRow row = sheet.createRow(0);
-        assertEquals(-1, row.getLastCellNum());
-        assertEquals(-1, row.getFirstCellNum());
-        row.createCell(1);
-        assertEquals(2, row.getLastCellNum());
-        assertEquals(1, row.getFirstCellNum());
-        row.createCell(3);
-        assertEquals(4, row.getLastCellNum());
-        assertEquals(1, row.getFirstCellNum());
-        row.removeCell(row.getCell(3));
-        assertEquals(2, row.getLastCellNum());
-        assertEquals(1, row.getFirstCellNum());
-        row.removeCell(row.getCell(1));
-        assertEquals(-1, row.getLastCellNum());
-        assertEquals(-1, row.getFirstCellNum());
-
-        // all cells on this row have been removed
-        // so check the row record actually writes it out as 0's
-        byte[] data = new byte[100];
-        row.getRowRecord().serialize(0, data);
-        assertEquals(0, data[6]);
-        assertEquals(0, data[8]);
-
-        workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
-        sheet = workbook.getSheetAt(0);
-
-        assertEquals(-1, sheet.getRow(0).getLastCellNum());
-        assertEquals(-1, sheet.getRow(0).getFirstCellNum());
-    }
-
     public void testMoveCell() {
         HSSFWorkbook workbook = new HSSFWorkbook();
         HSSFSheet sheet = workbook.createSheet();
@@ -184,149 +118,4 @@
         assertEquals(2, row.getFirstCellNum());
         assertEquals(6, row.getLastCellNum());
     }
-
-    public void testRowBounds() {
-      HSSFWorkbook workbook = new HSSFWorkbook();
-      HSSFSheet sheet = workbook.createSheet();
-      //Test low row bound
-      sheet.createRow(0);
-      //Test low row bound exception
-      try {
-        sheet.createRow(-1);
-        fail("IndexOutOfBoundsException should have been thrown");
-      } catch (IllegalArgumentException e) {
-        // expected during successful test
-        assertEquals("Invalid row number (-1) outside allowable range (0..65535)", e.getMessage());
-      }
-
-      //Test high row bound
-      sheet.createRow(65535);
-      //Test high row bound exception
-      try {
-        sheet.createRow(65536);
-        fail("IndexOutOfBoundsException should have been thrown");
-      } catch (IllegalArgumentException e) {
-        // expected during successful test
-        assertEquals("Invalid row number (65536) outside allowable range (0..65535)", e.getMessage());
-      }
-    }
-
-    /**
-     * Prior to patch 43901, POI was producing files with the wrong last-column
-     * number on the row
-     */
-    public void testLastCellNumIsCorrectAfterAddCell_bug43901(){
-        HSSFWorkbook book = new HSSFWorkbook();
-        HSSFSheet sheet = book.createSheet("test");
-        HSSFRow row = sheet.createRow(0);
-
-        // New row has last col -1
-        assertEquals(-1, row.getLastCellNum());
-        if(row.getLastCellNum() == 0) {
-            fail("Identified bug 43901");
-        }
-
-        // Create two cells, will return one higher
-        //  than that for the last number
-        row.createCell(0);
-        assertEquals(1, row.getLastCellNum());
-        row.createCell(255);
-        assertEquals(256, row.getLastCellNum());
-    }
-
-    /**
-     * Tests for the missing/blank cell policy stuff
-     */
-    public void testGetCellPolicy() {
-        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(0).setCellValue(new HSSFRichTextString("test"));
-        row.createCell(1).setCellValue(3.2);
-        row.createCell(4, HSSFCell.CELL_TYPE_BLANK);
-        row.createCell(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(0, row.getCell(0, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
-        assertEquals(1, row.getCell(1, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
-        assertEquals(2, row.getCell(2, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
-        assertEquals(3, row.getCell(3, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
-        assertEquals(4, row.getCell(4, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
-        assertEquals(5, row.getCell(5, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
-
-
-        // 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());
-    }
-
-    public void testRowHeight() {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheet = workbook.createSheet();
-        HSSFRow row1 = sheet.createRow(0);
-
-        assertEquals(0xFF, row1.getHeight());
-        assertEquals(sheet.getDefaultRowHeight(), row1.getHeight());
-
-        HSSFRow row2 = sheet.createRow(1);
-        row2.setHeight((short)400);
-
-        assertEquals(400, row2.getHeight());
-
-        workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
-        sheet = workbook.getSheetAt(0);
-
-        row1 = sheet.getRow(0);
-        assertEquals(0xFF, row1.getHeight());
-        assertEquals(sheet.getDefaultRowHeight(), row1.getHeight());
-
-        row2 = sheet.getRow(1);
-        assertEquals(400, row2.getHeight());
-    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java Fri Mar 27 11:50:52 2009
@@ -27,11 +27,13 @@
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.HSSFITestDataProvider;
 import org.apache.poi.hssf.model.Sheet;
 import org.apache.poi.hssf.model.DrawingManager2;
 import org.apache.poi.hssf.record.*;
 import org.apache.poi.ss.util.Region;
 import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.ss.usermodel.BaseTestSheet;
 import org.apache.poi.ddf.EscherDgRecord;
 
 /**
@@ -41,10 +43,15 @@
  * @author Glen Stampoultzis (glens at apache.org)
  * @author Andrew C. Oliver (acoliver apache org)
  */
-public final class TestHSSFSheet extends TestCase {
+public final class TestHSSFSheet extends BaseTestSheet {
 
-    private static HSSFWorkbook openSample(String sampleFileName) {
-        return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
+    @Override
+    protected HSSFITestDataProvider getTestDataProvider(){
+        return HSSFITestDataProvider.getInstance();
+    }
+
+    public void testTestGetSetMargin() {
+        baseTestGetSetMargin(new double[]{0.75, 0.75, 1.0, 1.0, 0.3, 0.3});
     }
 
     /**
@@ -140,138 +147,11 @@
         assertEquals(true, s.getRowSumsRight());
     }
 
-    public void testReadBooleans() {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheet = workbook.createSheet("Test boolean");
-        HSSFRow row = sheet.createRow(2);
-        HSSFCell cell = row.createCell(9);
-        cell.setCellValue(true);
-        cell = row.createCell(11);
-        cell.setCellValue(true);
-
-        workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
-
-        sheet = workbook.getSheetAt(0);
-        row = sheet.getRow(2);
-        assertNotNull(row);
-        assertEquals(2, row.getPhysicalNumberOfCells());
-    }
-
-    public void testRemoveRow() {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheet = workbook.createSheet("Test boolean");
-        HSSFRow row = sheet.createRow(2);
-        sheet.removeRow(row);
-    }
-
-    public void testRemoveZeroRow() {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheet = workbook.createSheet("Sheet1");
-        HSSFRow row = sheet.createRow(0);
-        try {
-            sheet.removeRow(row);
-        } catch (IllegalArgumentException e) {
-            if (e.getMessage().equals("Invalid row number (-1) outside allowable range (0..65535)")) {
-                throw new AssertionFailedError("Identified bug 45367");
-            }
-            throw e;
-        }
-    }
-
-    public void testCloneSheet() {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheet = workbook.createSheet("Test Clone");
-        HSSFRow row = sheet.createRow(0);
-        HSSFCell cell = row.createCell(0);
-        HSSFCell cell2 = row.createCell(1);
-        cell.setCellValue(new HSSFRichTextString("clone_test"));
-        cell2.setCellFormula("sin(1)");
-
-        HSSFSheet clonedSheet = workbook.cloneSheet(0);
-        HSSFRow clonedRow = clonedSheet.getRow(0);
-
-        //Check for a good clone
-        assertEquals(clonedRow.getCell(0).getRichStringCellValue().getString(), "clone_test");
-
-        //Check that the cells are not somehow linked
-        cell.setCellValue(new HSSFRichTextString("Difference Check"));
-        cell2.setCellFormula("cos(2)");
-        if ("Difference Check".equals(clonedRow.getCell(0).getRichStringCellValue().getString())) {
-            fail("string cell not properly cloned");
-        }
-        if ("COS(2)".equals(clonedRow.getCell(1).getCellFormula())) {
-            fail("formula cell not properly cloned");
-        }
-        assertEquals(clonedRow.getCell(0).getRichStringCellValue().getString(), "clone_test");
-        assertEquals(clonedRow.getCell(1).getCellFormula(), "SIN(1)");
-    }
-
-    /** tests that the sheet name for multiple clones of the same sheet is unique
-     * BUG 37416
-     */
-    public void testCloneSheetMultipleTimes() {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheet = workbook.createSheet("Test Clone");
-        HSSFRow row = sheet.createRow(0);
-        HSSFCell cell = row.createCell(0);
-        cell.setCellValue(new HSSFRichTextString("clone_test"));
-        //Clone the sheet multiple times
-        workbook.cloneSheet(0);
-        workbook.cloneSheet(0);
-
-        assertNotNull(workbook.getSheet("Test Clone"));
-        assertNotNull(workbook.getSheet("Test Clone (2)"));
-        assertEquals("Test Clone (3)", workbook.getSheetName(2));
-        assertNotNull(workbook.getSheet("Test Clone (3)"));
-
-        workbook.removeSheetAt(0);
-        workbook.removeSheetAt(0);
-        workbook.removeSheetAt(0);
-        workbook.createSheet("abc ( 123)");
-        workbook.cloneSheet(0);
-        assertEquals("abc (124)", workbook.getSheetName(1));
-    }
-
-    /**
-     * Setting landscape and portrait stuff on new sheets
-     */
-    public void testPrintSetupLandscapeNew() throws Exception {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheetL = workbook.createSheet("LandscapeS");
-        HSSFSheet sheetP = workbook.createSheet("LandscapeP");
-
-        // Check two aspects of the print setup
-        assertFalse(sheetL.getPrintSetup().getLandscape());
-        assertFalse(sheetP.getPrintSetup().getLandscape());
-        assertEquals(0, sheetL.getPrintSetup().getCopies());
-        assertEquals(0, sheetP.getPrintSetup().getCopies());
-
-        // Change one on each
-        sheetL.getPrintSetup().setLandscape(true);
-        sheetP.getPrintSetup().setCopies((short)3);
-
-        // Check taken
-        assertTrue(sheetL.getPrintSetup().getLandscape());
-        assertFalse(sheetP.getPrintSetup().getLandscape());
-        assertEquals(0, sheetL.getPrintSetup().getCopies());
-        assertEquals(3, sheetP.getPrintSetup().getCopies());
-
-        // Save and re-load, and check still there
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        workbook.write(baos);
-        workbook = new HSSFWorkbook(new ByteArrayInputStream(baos.toByteArray()));
-
-        assertTrue(sheetL.getPrintSetup().getLandscape());
-        assertFalse(sheetP.getPrintSetup().getLandscape());
-        assertEquals(0, sheetL.getPrintSetup().getCopies());
-        assertEquals(3, sheetP.getPrintSetup().getCopies());
-    }
-
     /**
      * Setting landscape and portrait stuff on existing sheets
      */
     public void testPrintSetupLandscapeExisting() {
-        HSSFWorkbook workbook = openSample("SimpleWithPageBreaks.xls");
+        HSSFWorkbook workbook = getTestDataProvider().openSampleWorkbook("SimpleWithPageBreaks.xls");
 
         assertEquals(3, workbook.getNumberOfSheets());
 
@@ -352,7 +232,7 @@
     }
 
     public void testGroupRowsExisting() {
-        HSSFWorkbook workbook = openSample("NoGutsRecords.xls");
+        HSSFWorkbook workbook = getTestDataProvider().openSampleWorkbook("NoGutsRecords.xls");
 
         HSSFSheet s = workbook.getSheetAt(0);
         HSSFRow r1 = s.getRow(0);
@@ -403,8 +283,8 @@
     }
 
     public void testGetDrawings() {
-        HSSFWorkbook wb1c = openSample("WithChart.xls");
-        HSSFWorkbook wb2c = openSample("WithTwoCharts.xls");
+        HSSFWorkbook wb1c = getTestDataProvider().openSampleWorkbook("WithChart.xls");
+        HSSFWorkbook wb2c = getTestDataProvider().openSampleWorkbook("WithTwoCharts.xls");
 
         // 1 chart sheet -> data on 1st, chart on 2nd
         assertNotNull(wb1c.getSheetAt(0).getDrawingPatriarch());
@@ -476,94 +356,12 @@
      * When removing one merged region, it would break
      *
      */
-    public void testRemoveMerged() {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet sheet = wb.createSheet();
-        CellRangeAddress region = new CellRangeAddress(0, 1, 0, 1);
-        sheet.addMergedRegion(region);
-        region = new CellRangeAddress(1, 2, 0, 1);
-        sheet.addMergedRegion(region);
-
-        sheet.removeMergedRegion(0);
-
-        region = sheet.getMergedRegion(0);
-        assertEquals("Left over region should be starting at row 1", 1, region.getFirstRow());
-
-        sheet.removeMergedRegion(0);
-
-        assertEquals("there should be no merged regions left!", 0, sheet.getNumMergedRegions());
-
-        //an, add, remove, get(0) would null pointer
-        sheet.addMergedRegion(region);
-        assertEquals("there should now be one merged region!", 1, sheet.getNumMergedRegions());
-        sheet.removeMergedRegion(0);
-        assertEquals("there should now be zero merged regions!", 0, sheet.getNumMergedRegions());
-        //add it again!
-        region.setLastRow(4);
-
-        sheet.addMergedRegion(region);
-        assertEquals("there should now be one merged region!", 1, sheet.getNumMergedRegions());
-
-        //should exist now!
-        assertTrue("there isn't more than one merged region in there", 1 <= sheet.getNumMergedRegions());
-        region = sheet.getMergedRegion(0);
-        assertEquals("the merged row to doesnt match the one we put in ", 4, region.getLastRow());
-    }
-
-    public void testShiftMerged() {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet sheet = wb.createSheet();
-        HSSFRow row = sheet.createRow(0);
-        HSSFCell cell = row.createCell(0);
-        cell.setCellValue(new HSSFRichTextString("first row, first cell"));
-
-        row = sheet.createRow(1);
-        cell = row.createCell(1);
-        cell.setCellValue(new HSSFRichTextString("second row, second cell"));
-
-        CellRangeAddress region = new CellRangeAddress(1, 1, 0, 1);
-        sheet.addMergedRegion(region);
-
-        sheet.shiftRows(1, 1, 1);
-
-        region = sheet.getMergedRegion(0);
-        assertEquals("Merged region not moved over to row 2", 2, region.getFirstRow());
-    }
-
-    /**
-     * Tests the display of gridlines, formulas, and rowcolheadings.
-     * @author Shawn Laubach (slaubach at apache dot org)
-     */
-    public void testDisplayOptions() {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet sheet = wb.createSheet();
-
-        assertEquals(sheet.isDisplayGridlines(), true);
-        assertEquals(sheet.isDisplayRowColHeadings(), true);
-        assertEquals(sheet.isDisplayFormulas(), false);
-        assertEquals(sheet.isDisplayZeros(), true);
-
-        sheet.setDisplayGridlines(false);
-        sheet.setDisplayRowColHeadings(false);
-        sheet.setDisplayFormulas(true);
-        sheet.setDisplayZeros(false);
-
-        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
-        sheet = wb.getSheetAt(0);
-
-        assertEquals(sheet.isDisplayGridlines(), false);
-        assertEquals(sheet.isDisplayRowColHeadings(), false);
-        assertEquals(sheet.isDisplayFormulas(), true);
-        assertEquals(sheet.isDisplayZeros(), false);
-    }
-
-
     /**
      * Make sure the excel file loads work
      *
      */
     public void testPageBreakFiles() {
-        HSSFWorkbook wb = openSample("SimpleWithPageBreaks.xls");
+        HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("SimpleWithPageBreaks.xls");
 
         HSSFSheet sheet = wb.getSheetAt(0);
         assertNotNull(sheet);
@@ -591,7 +389,7 @@
     }
 
     public void testDBCSName () {
-        HSSFWorkbook wb = openSample("DBCSSheetName.xls");
+        HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("DBCSSheetName.xls");
         wb.getSheetAt(1);
         assertEquals ("DBCS Sheet Name 2", wb.getSheetName(1),"\u090f\u0915" );
         assertEquals("DBCS Sheet Name 1", wb.getSheetName(0),"\u091c\u093e");
@@ -603,7 +401,7 @@
      * of the sheet when it is first opened.
      */
     public void testTopRow() {
-        HSSFWorkbook wb = openSample("SimpleWithPageBreaks.xls");
+        HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("SimpleWithPageBreaks.xls");
 
         HSSFSheet sheet = wb.getSheetAt(0);
         assertNotNull(sheet);
@@ -630,18 +428,6 @@
         assertEquals("formula", r.getCell(1).getCellFormula(), "A1*2");
     }
 
-    /** test that new default column styles get applied */
-    public void testDefaultColumnStyle() {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFCellStyle style = wb.createCellStyle();
-        HSSFSheet s = wb.createSheet();
-        s.setDefaultColumnStyle((short) 0, style);
-        HSSFRow r = s.createRow(0);
-        HSSFCell c = r.createCell(0);
-        assertEquals("style should match", style.getIndex(), c.getCellStyle().getIndex());
-    }
-
-
     /**
      *
      */
@@ -656,7 +442,7 @@
         workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
 
         //try adding empty rows in an existing worksheet
-        workbook = openSample("Simple.xls");
+        workbook = getTestDataProvider().openSampleWorkbook("Simple.xls");
 
         sheet = workbook.getSheetAt(0);
         for (int i = 3; i < 10; i++) sheet.createRow(i);
@@ -665,7 +451,7 @@
     }
 
     public void testAutoSizeColumn() {
-        HSSFWorkbook wb = openSample("43902.xls");
+        HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("43902.xls");
         String sheetName = "my sheet";
         HSSFSheet sheet = wb.getSheet(sheetName);
 
@@ -709,7 +495,7 @@
      * Setting ForceFormulaRecalculation on sheets
      */
     public void testForceRecalculation() throws Exception {
-        HSSFWorkbook workbook = openSample("UncalcedRecord.xls");
+        HSSFWorkbook workbook = getTestDataProvider().openSampleWorkbook("UncalcedRecord.xls");
 
         HSSFSheet sheet = workbook.getSheetAt(0);
         HSSFSheet sheet2 = workbook.getSheetAt(0);
@@ -778,7 +564,7 @@
 
     public void testColumnWidth() {
         //check we can correctly read column widths from a reference workbook
-        HSSFWorkbook wb = openSample("colwidth.xls");
+        HSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("colwidth.xls");
 
         //reference values
         int[] ref = {365, 548, 731, 914, 1097, 1280, 1462, 1645, 1828, 2011, 2194, 2377, 2560, 2742, 2925, 3108, 3291, 3474, 3657};
@@ -950,4 +736,5 @@
         assertFalse(cs.getFont(wbComplex).getItalic());
         assertEquals(HSSFFont.BOLDWEIGHT_BOLD, cs.getFont(wbComplex).getBoldweight());
     }
+
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java Fri Mar 27 11:50:52 2009
@@ -26,6 +26,7 @@
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.HSSFITestDataProvider;
 import org.apache.poi.hssf.model.HSSFFormulaParser;
 import org.apache.poi.hssf.model.Sheet;
 import org.apache.poi.hssf.record.NameRecord;
@@ -36,12 +37,15 @@
 import org.apache.poi.hssf.record.formula.Area3DPtg;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.TempFile;
+import org.apache.poi.ss.usermodel.BaseTestWorkbook;
+
 /**
  * Tests for {@link HSSFWorkbook}
  */
-public final class TestHSSFWorkbook extends TestCase {
-    private static HSSFWorkbook openSample(String sampleFileName) {
-        return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
+public final class TestHSSFWorkbook extends BaseTestWorkbook {
+    @Override
+    protected HSSFITestDataProvider getTestDataProvider(){
+        return HSSFITestDataProvider.getInstance();
     }
 
     public void testSetRepeatingRowsAndColumns() {
@@ -72,44 +76,6 @@
         }
     }
 
-    public void testDuplicateNames() {
-        HSSFWorkbook b = new HSSFWorkbook( );
-        b.createSheet("Sheet1");
-        b.createSheet();
-        b.createSheet("name1");
-        try {
-            b.createSheet("name1");
-            fail();
-        } catch (IllegalArgumentException pass) {
-            // expected during successful test
-        }
-        b.createSheet();
-        try {
-            b.setSheetName(3, "name1");
-            fail();
-        } catch (IllegalArgumentException pass) {
-            // expected during successful test
-        }
-
-        try {
-            b.setSheetName(3, "name1");
-            fail();
-        } catch (IllegalArgumentException pass) {
-            // expected during successful test
-        }
-
-        b.setSheetName( 3,  "name2" );
-        b.setSheetName( 3,  "name2" );
-        b.setSheetName( 3,  "name2" );
-
-        HSSFWorkbook c = new HSSFWorkbook( );
-        c.createSheet("Sheet1");
-        c.createSheet("Sheet2");
-        c.createSheet("Sheet3");
-        c.createSheet("Sheet4");
-
-    }
-
     public void testWindowOneDefaults() {
         HSSFWorkbook b = new HSSFWorkbook( );
         try {
@@ -147,17 +113,6 @@
     	assertEquals(false, w1.getHidden());
 	}
 
-    public void testSheetSelection() {
-        HSSFWorkbook b = new HSSFWorkbook();
-        b.createSheet("Sheet One");
-        b.createSheet("Sheet Two");
-        b.setActiveSheet(1);
-        b.setSelectedTab(1);
-        b.setFirstVisibleTab(1);
-        assertEquals(1, b.getActiveSheetIndex());
-        assertEquals(1, b.getFirstVisibleTab());
-    }
-
     public void testSheetClone() {
         // First up, try a simple file
         HSSFWorkbook b = new HSSFWorkbook();
@@ -170,7 +125,7 @@
         assertEquals(3, b.getNumberOfSheets());
 
         // Now try a problem one with drawing records in it
-        b = openSample("SheetWithDrawing.xls");
+        b = getTestDataProvider().openSampleWorkbook("SheetWithDrawing.xls");
         assertEquals(1, b.getNumberOfSheets());
         b.cloneSheet(0);
         assertEquals(2, b.getNumberOfSheets());
@@ -181,7 +136,7 @@
         HSSFSheet s;
 
         // Single chart, two sheets
-        b = openSample("44010-SingleChart.xls");
+        b = getTestDataProvider().openSampleWorkbook("44010-SingleChart.xls");
         assertEquals(2, b.getNumberOfSheets());
         assertEquals("Graph2", b.getSheetName(1));
         s = b.getSheetAt(1);
@@ -197,7 +152,7 @@
         // We've now called getDrawingPatriarch() so
         //  everything will be all screwy
         // So, start again
-        b = openSample("44010-SingleChart.xls");
+        b = getTestDataProvider().openSampleWorkbook("44010-SingleChart.xls");
 
         b = writeRead(b);
         assertEquals(2, b.getNumberOfSheets());
@@ -207,7 +162,7 @@
 
 
         // Two charts, three sheets
-        b = openSample("44010-TwoCharts.xls");
+        b = getTestDataProvider().openSampleWorkbook("44010-TwoCharts.xls");
         assertEquals(3, b.getNumberOfSheets());
 
         s = b.getSheetAt(1);
@@ -227,7 +182,7 @@
         // We've now called getDrawingPatriarch() so
         //  everything will be all screwy
         // So, start again
-        b = openSample("44010-TwoCharts.xls");
+        b = getTestDataProvider().openSampleWorkbook("44010-TwoCharts.xls");
 
         b = writeRead(b);
         assertEquals(3, b.getNumberOfSheets());
@@ -434,7 +389,7 @@
      *  that point to deleted sheets
      */
     public void testNamesToDeleteSheets() {
-        HSSFWorkbook b = openSample("30978-deleted.xls");
+        HSSFWorkbook b = getTestDataProvider().openSampleWorkbook("30978-deleted.xls");
         assertEquals(3, b.getNumberOfNames());
 
         // Sheet 2 is deleted

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java Fri Mar 27 11:50:52 2009
@@ -546,29 +546,4 @@
         assertTrue("file exists",file.exists());
     }
 
-    public void testParentReferences(){
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheet = workbook.createSheet();
-        assertSame(workbook, sheet.getWorkbook());
-
-        HSSFRow row = sheet.createRow(0);
-        assertSame(sheet, row.getSheet());
-
-        HSSFCell cell = row.createCell(1);
-        assertSame(sheet, cell.getSheet());
-        assertSame(row, cell.getRow());
-
-        workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
-        sheet = workbook.getSheetAt(0);
-        assertSame(workbook, sheet.getWorkbook());
-
-        row = sheet.getRow(0);
-        assertSame(sheet, row.getSheet());
-
-        cell = row.getCell(1);
-        assertSame(sheet, cell.getSheet());
-        assertSame(row, cell.getRow());
-
-
-    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java Fri Mar 27 11:50:52 2009
@@ -21,9 +21,12 @@
 import junit.framework.AssertionFailedError;
 import org.apache.poi.ss.ITestDataProvider;
 
+import java.util.Date;
+import java.util.Calendar;
+
 /**
- * Common superclass for testing {@link org.apache.poi.xssf.usermodel.XSSFCell}  and
- * {@link org.apache.poi.hssf.usermodel.HSSFCell}
+ * Common superclass for testing implementatiosn of
+ *  {@link org.apache.poi.ss.usermodel.Cell}
  */
 public abstract class BaseTestCell extends TestCase {
 
@@ -32,7 +35,7 @@
      */
     protected abstract ITestDataProvider getTestDataProvider();
 
-    public void baseTestSetValues() {
+    public void testSetValues() {
         Workbook book = getTestDataProvider().createWorkbook();
         Sheet sheet = book.createSheet("test");
         Row row = sheet.createRow(0);
@@ -43,24 +46,87 @@
         cell.setCellValue(1.2);
         assertEquals(1.2, cell.getNumericCellValue(), 0.0001);
         assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+        assertProhibitedValueAccess(cell, Cell.CELL_TYPE_BOOLEAN, Cell.CELL_TYPE_STRING,
+                Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_ERROR);
 
         cell.setCellValue(false);
         assertEquals(false, cell.getBooleanCellValue());
         assertEquals(Cell.CELL_TYPE_BOOLEAN, cell.getCellType());
+        cell.setCellValue(true);
+        assertEquals(true, cell.getBooleanCellValue());
+        assertProhibitedValueAccess(cell, Cell.CELL_TYPE_NUMERIC, Cell.CELL_TYPE_STRING,
+                Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_ERROR);
 
         cell.setCellValue(factory.createRichTextString("Foo"));
         assertEquals("Foo", cell.getRichStringCellValue().getString());
+        assertEquals("Foo", cell.getStringCellValue());
         assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
+        assertProhibitedValueAccess(cell, Cell.CELL_TYPE_NUMERIC, Cell.CELL_TYPE_BOOLEAN,
+                Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_ERROR);
 
-        cell.setCellValue(factory.createRichTextString("345"));
+        cell.setCellValue("345");
         assertEquals("345", cell.getRichStringCellValue().getString());
+        assertEquals("345", cell.getStringCellValue());
         assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
+        assertProhibitedValueAccess(cell, Cell.CELL_TYPE_NUMERIC, Cell.CELL_TYPE_BOOLEAN,
+                Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_ERROR);
+
+        Calendar c = Calendar.getInstance();
+        c.setTimeInMillis(123456789);
+        cell.setCellValue(c.getTime());
+        assertEquals(c.getTime().getTime(), cell.getDateCellValue().getTime());
+        assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+        assertProhibitedValueAccess(cell, Cell.CELL_TYPE_BOOLEAN, Cell.CELL_TYPE_STRING,
+                Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_ERROR);
+
+        cell.setCellValue(c);
+        assertEquals(c.getTime().getTime(), cell.getDateCellValue().getTime());
+        assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+        assertProhibitedValueAccess(cell, Cell.CELL_TYPE_BOOLEAN, Cell.CELL_TYPE_STRING,
+                Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_ERROR);
+
+        cell.setCellErrorValue(FormulaError.NA.getCode());
+        assertEquals(FormulaError.NA.getCode(), cell.getErrorCellValue());
+        assertEquals(Cell.CELL_TYPE_ERROR, cell.getCellType());
+        assertProhibitedValueAccess(cell, Cell.CELL_TYPE_NUMERIC, Cell.CELL_TYPE_BOOLEAN,
+                Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_STRING);
+    }
+
+    private void assertProhibitedValueAccess(Cell cell, int ... types){
+        for(int type : types){
+            try {
+                switch (type) {
+                    case Cell.CELL_TYPE_NUMERIC:
+                        cell.getNumericCellValue();
+                        fail();
+                        break;
+                    case Cell.CELL_TYPE_STRING:
+                        cell.getStringCellValue();
+                        fail();
+                        break;
+                    case Cell.CELL_TYPE_BOOLEAN:
+                        cell.getBooleanCellValue();
+                        fail();
+                        break;
+                    case Cell.CELL_TYPE_FORMULA:
+                        cell.getCellFormula();
+                        fail();
+                        break;
+                    case Cell.CELL_TYPE_ERROR:
+                        cell.getErrorCellValue();
+                        fail();
+                        break;
+                }
+            } catch (IllegalStateException e){
+                ;
+            }
+        }
     }
 
     /**
      * test that Boolean and Error types (BoolErrRecord) are supported properly.
      */
-    public void baseTestBoolErr() {
+    public void testBoolErr() {
 
         Workbook	 wb	 = getTestDataProvider().createWorkbook();
         Sheet		s	  = wb.createSheet("testSheet1");
@@ -101,7 +167,7 @@
     /**
      * test that Cell Styles being applied to formulas remain intact
      */
-    public void baseTestFormulaStyle() {
+    public void testFormulaStyle() {
 
         Workbook wb = getTestDataProvider().createWorkbook();
         Sheet s = wb.createSheet("testSheet1");
@@ -142,7 +208,7 @@
     }
 
     /**tests the toString() method of HSSFCell*/
-    public void baseTestToString() {
+    public void testToString() {
         Workbook wb = getTestDataProvider().createWorkbook();
         Row r = wb.createSheet("Sheet1").createRow(0);
         CreationHelper factory = wb.getCreationHelper();
@@ -173,7 +239,7 @@
     /**
      *  Test that setting cached formula result keeps the cell type
      */
-    public void baseTestSetFormulaValue() {
+    public void testSetFormulaValue() {
         Workbook wb = getTestDataProvider().createWorkbook();
         Sheet s = wb.createSheet();
         Row r = s.createRow(0);
@@ -274,4 +340,46 @@
         assertEquals(true, cell.getBooleanCellValue());
     }
 
+    /**
+     * Bug 40296:      HSSFCell.setCellFormula throws
+     *   ClassCastException if cell is created using HSSFRow.createCell(short column, int type)
+     */
+    public void test40296() {
+        Workbook wb = getTestDataProvider().createWorkbook();
+        Sheet workSheet = wb.createSheet("Sheet1");
+        Cell cell;
+        Row row = workSheet.createRow(0);
+
+        cell = row.createCell(0, Cell.CELL_TYPE_NUMERIC);
+        cell.setCellValue(1.0);
+        assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+        assertEquals(1.0, cell.getNumericCellValue());
+
+        cell = row.createCell(1, Cell.CELL_TYPE_NUMERIC);
+        cell.setCellValue(2.0);
+        assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+        assertEquals(2.0, cell.getNumericCellValue());
+
+        cell = row.createCell(2, Cell.CELL_TYPE_FORMULA);
+        cell.setCellFormula("SUM(A1:B1)");
+        assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
+        assertEquals("SUM(A1:B1)", cell.getCellFormula());
+
+        //serialize and check again
+        wb = getTestDataProvider().writeOutAndReadBack(wb);
+        row = wb.getSheetAt(0).getRow(0);
+        cell = row.getCell(0);
+        assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+        assertEquals(1.0, cell.getNumericCellValue());
+
+        cell = row.getCell(1);
+        assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+        assertEquals(2.0, cell.getNumericCellValue());
+
+        cell = row.getCell(2);
+        assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
+        assertEquals("SUM(A1:B1)", cell.getCellFormula());
+    }
+
+
 }
\ No newline at end of file

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java Fri Mar 27 11:50:52 2009
@@ -23,7 +23,7 @@
 import org.apache.poi.ss.ITestDataProvider;
 
 /**
- * Tests for {@link org.apache.poi.xssf.usermodel.XSSFDataFormat}
+ * Tests of implementation of {@link DataFormat}
  *
  */
 public abstract class BaseTestDataFormat extends TestCase {

Added: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java?rev=759112&view=auto
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java (added)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java Fri Mar 27 11:50:52 2009
@@ -0,0 +1,173 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.usermodel;
+
+import junit.framework.TestCase;
+import org.apache.poi.ss.ITestDataProvider;
+
+/**
+ * Tests of implementation of {@link org.apache.poi.ss.usermodel.Name}
+ *
+ */
+public abstract class BaseTestNamedRange extends TestCase {
+
+    /**
+     * @return an object that provides test data in HSSF / XSSF specific way
+     */
+    protected abstract ITestDataProvider getTestDataProvider();
+
+    public void testCreate(){
+        // Create a new workbook
+        Workbook wb = getTestDataProvider().createWorkbook();
+        Sheet sheet1 = wb.createSheet("Test1");
+        Sheet sheet2 = wb.createSheet("Testing Named Ranges");
+
+        Name name1 = wb.createName();
+        name1.setNameName("testOne");
+
+        //setting a duplicate name should throw IllegalArgumentException
+        Name name2 = wb.createName();
+        try {
+            name2.setNameName("testOne");
+            fail("expected exception");
+        } catch (IllegalArgumentException e){
+            assertEquals("The workbook already contains this name: testOne", e.getMessage());
+        }
+        //the check for duplicates is case-insensitive
+        try {
+            name2.setNameName("TESTone");
+            fail("expected exception");
+        } catch (IllegalArgumentException e){
+            assertEquals("The workbook already contains this name: TESTone", e.getMessage());
+        }
+
+        name2.setNameName("testTwo");
+
+        String ref1 = "Test1!$A$1:$B$1";
+        name1.setRefersToFormula(ref1);
+        assertEquals(ref1, name1.getRefersToFormula());
+        assertEquals("Test1", name1.getSheetName());
+
+        String ref2 = "'Testing Named Ranges'!$A$1:$B$1";
+        name1.setRefersToFormula(ref2);
+        assertEquals("'Testing Named Ranges'!$A$1:$B$1", name1.getRefersToFormula());
+        assertEquals("Testing Named Ranges", name1.getSheetName());
+
+        assertEquals(-1, name1.getSheetIndex());
+        name1.setSheetIndex(-1);
+        assertEquals(-1, name1.getSheetIndex());
+        try {
+            name1.setSheetIndex(2);
+            fail("should throw IllegalArgumentException");
+        } catch(IllegalArgumentException e){
+            assertEquals("Sheet index (2) is out of range (0..1)", e.getMessage());
+        }
+
+        name1.setSheetIndex(1);
+        assertEquals(1, name1.getSheetIndex());
+
+        //-1 means the name applies to the entire workbook
+        name1.setSheetIndex(-1);
+        assertEquals(-1, name1.getSheetIndex());
+    }
+
+    public void testUnicodeNamedRange() {
+        Workbook workBook = getTestDataProvider().createWorkbook();
+        workBook.createSheet("Test");
+        Name name = workBook.createName();
+        name.setNameName("\u03B1");
+        name.setRefersToFormula("Test!$D$3:$E$8");
+
+
+        Workbook workBook2 = getTestDataProvider().writeOutAndReadBack(workBook);
+        Name name2 = workBook2.getNameAt(0);
+
+        assertEquals("\u03B1", name2.getNameName());
+        assertEquals("Test!$D$3:$E$8", name2.getRefersToFormula());
+    }
+
+    public void testAddRemove() {
+        Workbook wb = getTestDataProvider().createWorkbook();
+        assertEquals(0, wb.getNumberOfNames());
+        Name name1 = wb.createName();
+        name1.setNameName("name1");
+        assertEquals(1, wb.getNumberOfNames());
+
+        Name name2 = wb.createName();
+        name2.setNameName("name2");
+        assertEquals(2, wb.getNumberOfNames());
+
+        Name name3 = wb.createName();
+        name3.setNameName("name3");
+        assertEquals(3, wb.getNumberOfNames());
+
+        wb.removeName("name2");
+        assertEquals(2, wb.getNumberOfNames());
+
+        wb.removeName(0);
+        assertEquals(1, wb.getNumberOfNames());
+    }
+
+    public void testScope() {
+        Workbook wb = getTestDataProvider().createWorkbook();
+        wb.createSheet();
+        wb.createSheet();
+
+        Name name;
+
+        name = wb.createName();
+        name.setNameName("aaa");
+        name = wb.createName();
+        try {
+            name.setNameName("aaa");
+            fail("Expected exception");
+        } catch(Exception e){
+            assertEquals("The workbook already contains this name: aaa", e.getMessage());
+        }
+
+        name = wb.createName();
+        name.setSheetIndex(0);
+        name.setNameName("aaa");
+        name = wb.createName();
+        name.setSheetIndex(0);
+        try {
+            name.setNameName("aaa");
+            fail("Expected exception");
+        } catch(Exception e){
+            assertEquals("The sheet already contains this name: aaa", e.getMessage());
+        }
+
+        name = wb.createName();
+        name.setSheetIndex(1);
+        name.setNameName("aaa");
+        name = wb.createName();
+        name.setSheetIndex(1);
+        try {
+            name.setNameName("aaa");
+            fail("Expected exception");
+        } catch(Exception e){
+            assertEquals("The sheet already contains this name: aaa", e.getMessage());
+        }
+
+        int cnt = 0;
+        for (int i = 0; i < wb.getNumberOfNames(); i++) {
+            if("aaa".equals(wb.getNameAt(i).getNameName())) cnt++;
+        }
+        assertEquals(3, cnt);
+    }
+}
\ No newline at end of file

Propchange: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java
------------------------------------------------------------------------------
    svn:executable = *

Added: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java?rev=759112&view=auto
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java (added)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java Fri Mar 27 11:50:52 2009
@@ -0,0 +1,376 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.usermodel;
+
+import junit.framework.TestCase;
+import org.apache.poi.ss.ITestDataProvider;
+
+import java.util.Iterator;
+
+/**
+ * A base class for testing implementations of
+ * {@link org.apache.poi.ss.usermodel.Row}
+ */
+public abstract class BaseTestRow extends TestCase {
+
+    /**
+     * @return an object that provides test data in  / XSSF specific way
+     */
+    protected abstract ITestDataProvider getTestDataProvider();
+
+
+    public void testLastAndFirstColumns() {
+        Workbook workbook = getTestDataProvider().createWorkbook();
+        Sheet sheet = workbook.createSheet();
+        Row row = sheet.createRow(0);
+        assertEquals(-1, row.getFirstCellNum());
+        assertEquals(-1, row.getLastCellNum());
+
+        row.createCell(2);
+        assertEquals(2, row.getFirstCellNum());
+        assertEquals(3, row.getLastCellNum());
+
+        row.createCell(1);
+        assertEquals(1, row.getFirstCellNum());
+        assertEquals(3, row.getLastCellNum());
+
+        // check the exact case reported in 'bug' 43901 - notice that the cellNum is '0' based
+        row.createCell(3);
+        assertEquals(1, row.getFirstCellNum());
+        assertEquals(4, row.getLastCellNum());
+    }
+
+    /**
+     * Make sure that there is no cross-talk between rows especially with getFirstCellNum and getLastCellNum
+     * This test was added in response to bug report 44987.
+     */
+    public void testBoundsInMultipleRows() {
+        Workbook workbook = getTestDataProvider().createWorkbook();
+        Sheet sheet = workbook.createSheet();
+        Row rowA = sheet.createRow(0);
+
+        rowA.createCell(10);
+        rowA.createCell(5);
+        assertEquals(5, rowA.getFirstCellNum());
+        assertEquals(11, rowA.getLastCellNum());
+
+        Row rowB = sheet.createRow(1);
+        rowB.createCell(15);
+        rowB.createCell(30);
+        assertEquals(15, rowB.getFirstCellNum());
+        assertEquals(31, rowB.getLastCellNum());
+
+        assertEquals(5, rowA.getFirstCellNum());
+        assertEquals(11, rowA.getLastCellNum());
+        rowA.createCell(50);
+        assertEquals(51, rowA.getLastCellNum());
+
+        assertEquals(31, rowB.getLastCellNum());
+    }
+
+    public void testRemoveCell() {
+        Workbook workbook = getTestDataProvider().createWorkbook();
+        Sheet sheet = workbook.createSheet();
+        Row row = sheet.createRow(0);
+
+        assertEquals(0, row.getPhysicalNumberOfCells());
+        assertEquals(-1, row.getLastCellNum());
+        assertEquals(-1, row.getFirstCellNum());
+
+        row.createCell(1);
+        assertEquals(2, row.getLastCellNum());
+        assertEquals(1, row.getFirstCellNum());
+        assertEquals(1, row.getPhysicalNumberOfCells());
+        row.createCell(3);
+        assertEquals(4, row.getLastCellNum());
+        assertEquals(1, row.getFirstCellNum());
+        assertEquals(2, row.getPhysicalNumberOfCells());
+        row.removeCell(row.getCell(3));
+        assertEquals(2, row.getLastCellNum());
+        assertEquals(1, row.getFirstCellNum());
+        assertEquals(1, row.getPhysicalNumberOfCells());
+        row.removeCell(row.getCell(1));
+        assertEquals(-1, row.getLastCellNum());
+        assertEquals(-1, row.getFirstCellNum());
+        assertEquals(0, row.getPhysicalNumberOfCells());
+
+        workbook = getTestDataProvider().writeOutAndReadBack(workbook);
+        sheet = workbook.getSheetAt(0);
+        row = sheet.getRow(0);
+        assertEquals(-1, row.getLastCellNum());
+        assertEquals(-1, row.getFirstCellNum());
+        assertEquals(0, row.getPhysicalNumberOfCells());
+    }
+
+    public void baseTestRowBounds(int maxRowNum) {
+        Workbook workbook = getTestDataProvider().createWorkbook();
+        Sheet sheet = workbook.createSheet();
+        //Test low row bound
+        sheet.createRow(0);
+        //Test low row bound exception
+        try {
+            sheet.createRow(-1);
+            fail("expected exception");
+        } catch (IllegalArgumentException e) {
+            // expected during successful test
+            assertTrue(e.getMessage().startsWith("Invalid row number (-1)"));
+        }
+
+        //Test high row bound
+        sheet.createRow(maxRowNum);
+        //Test high row bound exception
+        try {
+            sheet.createRow(maxRowNum + 1);
+            fail("expected exception");
+        } catch (IllegalArgumentException e) {
+            // expected during successful test
+            assertEquals("Invalid row number ("+(maxRowNum + 1)+") outside allowable range (0.."+maxRowNum+")", e.getMessage());
+        }
+    }
+
+    public void baseTestCellBounds(int maxCellNum) {
+        Workbook workbook = getTestDataProvider().createWorkbook();
+        Sheet sheet = workbook.createSheet();
+
+        Row row = sheet.createRow(0);
+        //Test low cell bound
+        try {
+            Cell cell = row.createCell(-1);
+            fail("expected exception");
+        } catch (IllegalArgumentException e) {
+            // expected during successful test
+            assertTrue(e.getMessage().startsWith("Invalid column index (-1)"));
+        }
+
+        row.createCell(maxCellNum);
+
+        //Test high cell bound
+        try {
+            Cell cell = row.createCell(maxCellNum + 1);
+            fail("expected exception");
+        } catch (IllegalArgumentException e) {
+            // expected during successful test
+            assertTrue(e.getMessage().startsWith("Invalid column index ("+(maxCellNum+1)+")"));
+        }
+    }
+
+    /**
+     * Prior to patch 43901, POI was producing files with the wrong last-column
+     * number on the row
+     */
+    public void testLastCellNumIsCorrectAfterAddCell_bug43901(){
+        Workbook workbook = getTestDataProvider().createWorkbook();
+        Sheet sheet = workbook.createSheet("test");
+        Row row = sheet.createRow(0);
+
+        // New row has last col -1
+        assertEquals(-1, row.getLastCellNum());
+        if(row.getLastCellNum() == 0) {
+            fail("Identified bug 43901");
+        }
+
+        // Create two cells, will return one higher
+        //  than that for the last number
+        row.createCell(0);
+        assertEquals(1, row.getLastCellNum());
+        row.createCell(255);
+        assertEquals(256, row.getLastCellNum());
+    }
+
+    /**
+     * Tests for the missing/blank cell policy stuff
+     */
+    public void testGetCellPolicy() {
+        Workbook workbook = getTestDataProvider().createWorkbook();
+        Sheet sheet = workbook.createSheet("test");
+        Row row = sheet.createRow(0);
+
+        // 0 -> string
+        // 1 -> num
+        // 2 missing
+        // 3 missing
+        // 4 -> blank
+        // 5 -> num
+        row.createCell(0).setCellValue("test");
+        row.createCell(1).setCellValue(3.2);
+        row.createCell(4, Cell.CELL_TYPE_BLANK);
+        row.createCell(5).setCellValue(4);
+
+        // First up, no policy given, uses default
+        assertEquals(Cell.CELL_TYPE_STRING,  row.getCell(0).getCellType());
+        assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(1).getCellType());
+        assertEquals(null, row.getCell(2));
+        assertEquals(null, row.getCell(3));
+        assertEquals(Cell.CELL_TYPE_BLANK,   row.getCell(4).getCellType());
+        assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(5).getCellType());
+
+        // RETURN_NULL_AND_BLANK - same as default
+        assertEquals(Cell.CELL_TYPE_STRING,  row.getCell(0, Row.RETURN_NULL_AND_BLANK).getCellType());
+        assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(1, Row.RETURN_NULL_AND_BLANK).getCellType());
+        assertEquals(null, row.getCell(2, Row.RETURN_NULL_AND_BLANK));
+        assertEquals(null, row.getCell(3, Row.RETURN_NULL_AND_BLANK));
+        assertEquals(Cell.CELL_TYPE_BLANK,   row.getCell(4, Row.RETURN_NULL_AND_BLANK).getCellType());
+        assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(5, Row.RETURN_NULL_AND_BLANK).getCellType());
+
+        // RETURN_BLANK_AS_NULL - nearly the same
+        assertEquals(Cell.CELL_TYPE_STRING,  row.getCell(0, Row.RETURN_BLANK_AS_NULL).getCellType());
+        assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(1, Row.RETURN_BLANK_AS_NULL).getCellType());
+        assertEquals(null, row.getCell(2, Row.RETURN_BLANK_AS_NULL));
+        assertEquals(null, row.getCell(3, Row.RETURN_BLANK_AS_NULL));
+        assertEquals(null, row.getCell(4, Row.RETURN_BLANK_AS_NULL));
+        assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(5, Row.RETURN_BLANK_AS_NULL).getCellType());
+
+        // CREATE_NULL_AS_BLANK - creates as needed
+        assertEquals(Cell.CELL_TYPE_STRING,  row.getCell(0, Row.CREATE_NULL_AS_BLANK).getCellType());
+        assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(1, Row.CREATE_NULL_AS_BLANK).getCellType());
+        assertEquals(Cell.CELL_TYPE_BLANK,   row.getCell(2, Row.CREATE_NULL_AS_BLANK).getCellType());
+        assertEquals(Cell.CELL_TYPE_BLANK,   row.getCell(3, Row.CREATE_NULL_AS_BLANK).getCellType());
+        assertEquals(Cell.CELL_TYPE_BLANK,   row.getCell(4, Row.CREATE_NULL_AS_BLANK).getCellType());
+        assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(5, Row.CREATE_NULL_AS_BLANK).getCellType());
+
+        // Check created ones get the right column
+        assertEquals(0, row.getCell(0, Row.CREATE_NULL_AS_BLANK).getColumnIndex());
+        assertEquals(1, row.getCell(1, Row.CREATE_NULL_AS_BLANK).getColumnIndex());
+        assertEquals(2, row.getCell(2, Row.CREATE_NULL_AS_BLANK).getColumnIndex());
+        assertEquals(3, row.getCell(3, Row.CREATE_NULL_AS_BLANK).getColumnIndex());
+        assertEquals(4, row.getCell(4, Row.CREATE_NULL_AS_BLANK).getColumnIndex());
+        assertEquals(5, row.getCell(5, Row.CREATE_NULL_AS_BLANK).getColumnIndex());
+
+
+        // Now change the cell policy on the workbook, check
+        //  that that is now used if no policy given
+        workbook.setMissingCellPolicy(Row.RETURN_BLANK_AS_NULL);
+
+        assertEquals(Cell.CELL_TYPE_STRING,  row.getCell(0).getCellType());
+        assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(1).getCellType());
+        assertEquals(null, row.getCell(2));
+        assertEquals(null, row.getCell(3));
+        assertEquals(null, row.getCell(4));
+        assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(5).getCellType());
+    }
+
+    public void testRowHeight() {
+        Workbook workbook = getTestDataProvider().createWorkbook();
+        Sheet sheet = workbook.createSheet();
+        Row row1 = sheet.createRow(0);
+
+        assertEquals(sheet.getDefaultRowHeight(), row1.getHeight());
+
+        sheet.setDefaultRowHeightInPoints(20);
+        row1.setHeight((short)-1); //reset the row height
+        assertEquals(20.0f, row1.getHeightInPoints());
+        assertEquals(20*20, row1.getHeight());
+
+        Row row2 = sheet.createRow(1);
+        row2.setHeight((short)310);
+        assertEquals(310, row2.getHeight());
+        assertEquals((float)310/20, row2.getHeightInPoints());
+
+        Row row3 = sheet.createRow(2);
+        row3.setHeightInPoints(25.5f);
+        assertEquals((short)(25.5f*20), row3.getHeight());
+        assertEquals(25.5f, row3.getHeightInPoints());
+
+        Row row4 = sheet.createRow(3);
+        assertFalse(row4.getZeroHeight());
+        row4.setZeroHeight(true);
+        assertTrue(row4.getZeroHeight());
+
+        workbook = getTestDataProvider().writeOutAndReadBack(workbook);
+        sheet = workbook.getSheetAt(0);
+
+        row1 = sheet.getRow(0);
+        row2 = sheet.getRow(1);
+        row3 = sheet.getRow(2);
+        row4 = sheet.getRow(3);
+        assertEquals(20.0f, row1.getHeightInPoints());
+        assertEquals(20*20, row1.getHeight());
+
+        assertEquals(310, row2.getHeight());
+        assertEquals((float)310/20, row2.getHeightInPoints());
+
+        assertEquals((short)(25.5f*20), row3.getHeight());
+        assertEquals(25.5f, row3.getHeightInPoints());
+
+        assertFalse(row1.getZeroHeight());
+        assertFalse(row2.getZeroHeight());
+        assertFalse(row3.getZeroHeight());
+        assertTrue(row4.getZeroHeight());
+    }
+
+    /**
+     * Test adding cells to a row in various places and see if we can find them again.
+     */
+    public void testCellIterator() {
+        Workbook wb = getTestDataProvider().createWorkbook();
+        Sheet sheet = wb.createSheet();
+        Row row = sheet.createRow(0);
+
+        // One cell at the beginning
+        Cell cell1 = row.createCell(1);
+        Iterator<Cell> it = row.cellIterator();
+        assertTrue(it.hasNext());
+        assertTrue(cell1 == it.next());
+        assertFalse(it.hasNext());
+
+        // Add another cell at the end
+        Cell cell2 = row.createCell(99);
+        it = row.cellIterator();
+        assertTrue(it.hasNext());
+        assertTrue(cell1 == it.next());
+        assertTrue(it.hasNext());
+        assertTrue(cell2 == it.next());
+
+        // Add another cell at the beginning
+        Cell cell3 = row.createCell(0);
+        it = row.cellIterator();
+        assertTrue(it.hasNext());
+        assertTrue(cell3 == it.next());
+        assertTrue(it.hasNext());
+        assertTrue(cell1 == it.next());
+        assertTrue(it.hasNext());
+        assertTrue(cell2 == it.next());
+
+        // Replace cell1
+        Cell cell4 = row.createCell(1);
+        it = row.cellIterator();
+        assertTrue(it.hasNext());
+        assertTrue(cell3 == it.next());
+        assertTrue(it.hasNext());
+        assertTrue(cell4 == it.next());
+        assertTrue(it.hasNext());
+        assertTrue(cell2 == it.next());
+        assertFalse(it.hasNext());
+
+        // Add another cell, specifying the cellType
+        Cell cell5 = row.createCell(2, Cell.CELL_TYPE_STRING);
+        it = row.cellIterator();
+        assertNotNull(cell5);
+        assertTrue(it.hasNext());
+        assertTrue(cell3 == it.next());
+        assertTrue(it.hasNext());
+        assertTrue(cell4 == it.next());
+        assertTrue(it.hasNext());
+        assertTrue(cell5 == it.next());
+        assertTrue(it.hasNext());
+        assertTrue(cell2 == it.next());
+        assertEquals(Cell.CELL_TYPE_STRING, cell5.getCellType());
+    }
+
+
+}
\ No newline at end of file

Propchange: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java
------------------------------------------------------------------------------
    svn:executable = *



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


Mime
View raw message