poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r655278 [2/2] - in /poi/trunk/src: documentation/content/xdocs/ java/org/apache/poi/hssf/model/ java/org/apache/poi/hssf/record/ java/org/apache/poi/hssf/record/aggregates/ java/org/apache/poi/hssf/usermodel/ testcases/org/apache/poi/hssf/ ...
Date Sun, 11 May 2008 08:15:39 GMT
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java?rev=655278&r1=655277&r2=655278&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java Sun May 11 01:15:39 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,7 +14,6 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.model;
 
@@ -34,8 +32,7 @@
  *
  * @author Glen Stampoultzis (glens at apache.org)
  */
-public class TestSheet extends TestCase
-{
+public final class TestSheet extends TestCase {
     public void testCreateSheet() throws Exception
     {
         // Check we're adding row and cell aggregates
@@ -76,6 +73,21 @@
         if ((regionsToAdd % 1027) != 0)
             recordsExpected++;
         assertTrue("The " + regionsToAdd + " merged regions should have been spread out over
" + recordsExpected + " records, not " + recordsAdded, recordsAdded == recordsExpected);
+        // Check we can't add one with invalid date
+        try {
+            sheet.addMergedRegion(10, (short)10, 9, (short)12);
+            fail("Expected an exception to occur");
+        } catch(IllegalArgumentException e) {
+            // occurs during successful test
+            assertEquals("The 'to' row (9) must not be less than the 'from' row (10)", e.getMessage());
+        }
+        try {
+            sheet.addMergedRegion(10, (short)10, 12, (short)9);
+            fail("Expected an exception to occur");
+        } catch(IllegalArgumentException e) {
+            // occurs during successful test
+            assertEquals("The 'to' col (9) must not be less than the 'from' col (10)", e.getMessage());
+        }
     }
 
     public void testRemoveMergedRegion()
@@ -113,9 +125,9 @@
 
         MergeCellsRecord merged = new MergeCellsRecord();
         merged.addArea(0, (short)0, 1, (short)2);
-        records.add(new RowRecord());
-        records.add(new RowRecord());
-        records.add(new RowRecord());
+        records.add(new RowRecord(0));
+        records.add(new RowRecord(1));
+        records.add(new RowRecord(2));
         records.add(merged);
 
         Sheet sheet = Sheet.createSheet(records, 0);
@@ -142,20 +154,11 @@
      */
     public void testRowAggregation() {
         List records = new ArrayList();
-        RowRecord row = new RowRecord();
-        row.setRowNumber(0);
-        records.add(row);
-
-        row = new RowRecord();
-        row.setRowNumber(1);
-        records.add(row);
 
+        records.add(new RowRecord(0));
+        records.add(new RowRecord(1));
         records.add(new StringRecord());
-
-        row = new RowRecord();
-        row.setRowNumber(2);
-        records.add(row);
-
+        records.add(new RowRecord(2));
 
         Sheet sheet = Sheet.createSheet(records, 0);
         assertNotNull("Row [2] was skipped", sheet.getRow(2));
@@ -197,9 +200,9 @@
         Iterator iterator = sheet.getRowBreaks();
         while (iterator.hasNext()) {
             PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-            int main = (int)breakItem.main;
+            int main = breakItem.main;
             if (main != 0 && main != 10 && main != 11) fail("Invalid page
break");
-            if (main == 0) 	is0 = true;
+            if (main == 0)     is0 = true;
             if (main == 10) is10= true;
             if (main == 11) is11 = true;
         }
@@ -216,8 +219,6 @@
         assertFalse("row should be removed", sheet.isRowBroken(10));
 
         assertEquals("no more breaks", 0, sheet.getNumRowBreaks());
-
-
     }
 
     /**
@@ -256,10 +257,10 @@
         Iterator iterator = sheet.getColumnBreaks();
         while (iterator.hasNext()) {
             PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-            int main = (int)breakItem.main;
+            int main = breakItem.main;
             if (main != 0 && main != 1 && main != 10 && main != 15)
fail("Invalid page break");
-            if (main == 0) 	is0 = true;
-            if (main == 1) 	is1 = true;
+            if (main == 0)  is0 = true;
+            if (main == 1)  is1 = true;
             if (main == 10) is10= true;
             if (main == 15) is15 = true;
         }
@@ -286,72 +287,69 @@
      * works as designed.
      */
     public void testXFIndexForColumn() {
-        try{
-            final short TEST_IDX = 10;
-            final short DEFAULT_IDX = 0xF; // 15
-            short xfindex = Short.MIN_VALUE;
-            Sheet sheet = Sheet.createSheet();
-            
-            // without ColumnInfoRecord
-            xfindex = sheet.getXFIndexForColAt((short) 0);
-            assertEquals(DEFAULT_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 1);
-            assertEquals(DEFAULT_IDX, xfindex);
-            
-            ColumnInfoRecord nci = ( ColumnInfoRecord ) sheet.createColInfo();
-            sheet.columns.insertColumn(nci);
-            
-            // single column ColumnInfoRecord
-            nci.setFirstColumn((short) 2);
-            nci.setLastColumn((short) 2);
-            nci.setXFIndex(TEST_IDX);            
-            xfindex = sheet.getXFIndexForColAt((short) 0);
-            assertEquals(DEFAULT_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 1);
-            assertEquals(DEFAULT_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 2);
-            assertEquals(TEST_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 3);
-            assertEquals(DEFAULT_IDX, xfindex);
-
-            // ten column ColumnInfoRecord
-            nci.setFirstColumn((short) 2);
-            nci.setLastColumn((short) 11);
-            nci.setXFIndex(TEST_IDX);            
-            xfindex = sheet.getXFIndexForColAt((short) 1);
-            assertEquals(DEFAULT_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 2);
-            assertEquals(TEST_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 6);
-            assertEquals(TEST_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 11);
-            assertEquals(TEST_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 12);
-            assertEquals(DEFAULT_IDX, xfindex);
-
-            // single column ColumnInfoRecord starting at index 0
-            nci.setFirstColumn((short) 0);
-            nci.setLastColumn((short) 0);
-            nci.setXFIndex(TEST_IDX);            
-            xfindex = sheet.getXFIndexForColAt((short) 0);
-            assertEquals(TEST_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 1);
-            assertEquals(DEFAULT_IDX, xfindex);
-
-            // ten column ColumnInfoRecord starting at index 0
-            nci.setFirstColumn((short) 0);
-            nci.setLastColumn((short) 9);
-            nci.setXFIndex(TEST_IDX);            
-            xfindex = sheet.getXFIndexForColAt((short) 0);
-            assertEquals(TEST_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 7);
-            assertEquals(TEST_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 9);
-            assertEquals(TEST_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 10);
-            assertEquals(DEFAULT_IDX, xfindex);
-        }
-        catch(Exception e){e.printStackTrace();fail(e.getMessage());}
+        final short TEST_IDX = 10;
+        final short DEFAULT_IDX = 0xF; // 15
+        short xfindex = Short.MIN_VALUE;
+        Sheet sheet = Sheet.createSheet();
+        
+        // without ColumnInfoRecord
+        xfindex = sheet.getXFIndexForColAt((short) 0);
+        assertEquals(DEFAULT_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 1);
+        assertEquals(DEFAULT_IDX, xfindex);
+        
+        ColumnInfoRecord nci = ( ColumnInfoRecord ) sheet.createColInfo();
+        sheet.columns.insertColumn(nci);
+        
+        // single column ColumnInfoRecord
+        nci.setFirstColumn((short) 2);
+        nci.setLastColumn((short) 2);
+        nci.setXFIndex(TEST_IDX);            
+        xfindex = sheet.getXFIndexForColAt((short) 0);
+        assertEquals(DEFAULT_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 1);
+        assertEquals(DEFAULT_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 2);
+        assertEquals(TEST_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 3);
+        assertEquals(DEFAULT_IDX, xfindex);
+
+        // ten column ColumnInfoRecord
+        nci.setFirstColumn((short) 2);
+        nci.setLastColumn((short) 11);
+        nci.setXFIndex(TEST_IDX);            
+        xfindex = sheet.getXFIndexForColAt((short) 1);
+        assertEquals(DEFAULT_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 2);
+        assertEquals(TEST_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 6);
+        assertEquals(TEST_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 11);
+        assertEquals(TEST_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 12);
+        assertEquals(DEFAULT_IDX, xfindex);
+
+        // single column ColumnInfoRecord starting at index 0
+        nci.setFirstColumn((short) 0);
+        nci.setLastColumn((short) 0);
+        nci.setXFIndex(TEST_IDX);            
+        xfindex = sheet.getXFIndexForColAt((short) 0);
+        assertEquals(TEST_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 1);
+        assertEquals(DEFAULT_IDX, xfindex);
+
+        // ten column ColumnInfoRecord starting at index 0
+        nci.setFirstColumn((short) 0);
+        nci.setLastColumn((short) 9);
+        nci.setXFIndex(TEST_IDX);            
+        xfindex = sheet.getXFIndexForColAt((short) 0);
+        assertEquals(TEST_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 7);
+        assertEquals(TEST_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 9);
+        assertEquals(TEST_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 10);
+        assertEquals(DEFAULT_IDX, xfindex);
     }
-
 }
+

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java?rev=655278&r1=655277&r2=655278&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java Sun May 11
01:15:39 2008
@@ -19,125 +19,18 @@
 
 import java.lang.reflect.Field;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.record.ColumnInfoRecord;
-import org.apache.poi.hssf.record.MergeCellsRecord;
-import org.apache.poi.hssf.record.PageBreakRecord;
-import org.apache.poi.hssf.record.RowRecord;
-import org.apache.poi.hssf.record.StringRecord;
 
 /**
  * @author Tony Poppleton
  */
-public class TestSheetAdditional extends TestCase
-{
-	/**
-	 * Constructor for SheetTest.
-	 * @param arg0
-	 */
-	public TestSheetAdditional(String arg0)
-	{
-		super(arg0);
-	}
+public final class TestSheetAdditional extends TestCase {
 	
-	public void testAddMergedRegion()
-	{
-		Sheet sheet = Sheet.createSheet();
-		int regionsToAdd = 4096;
-		int startRecords = sheet.getRecords().size();
-		
-		//simple test that adds a load of regions
-		for (int n = 0; n < regionsToAdd; n++)
-		{
-			int index = sheet.addMergedRegion(0, (short) 0, 1, (short) 1);
-			assertTrue("Merged region index expected to be " + n + " got " + index, index == n);
-		}
-		
-		//test all the regions were indeed added 
-		assertTrue(sheet.getNumMergedRegions() == regionsToAdd);
-		
-		//test that the regions were spread out over the appropriate number of records
-		int recordsAdded    = sheet.getRecords().size() - startRecords;
-		int recordsExpected = regionsToAdd/1027;
-		if ((regionsToAdd % 1027) != 0)
-			recordsExpected++;
-		assertTrue("The " + regionsToAdd + " merged regions should have been spread out over "
+ recordsExpected + " records, not " + recordsAdded, recordsAdded == recordsExpected);
-		
-		// Check we can't add one with invalud date
-		try {
-			sheet.addMergedRegion(10, (short)10, 9, (short)12);
-			fail();
-		} catch(IllegalArgumentException e) {}
-		try {
-			sheet.addMergedRegion(10, (short)10, 12, (short)9);
-			fail();
-		} catch(IllegalArgumentException e) {}
-	}
-
-	public void testRemoveMergedRegion()
-	{
-		Sheet sheet = Sheet.createSheet();
-		int regionsToAdd = 4096;
-		
-		for (int n = 0; n < regionsToAdd; n++)
-			sheet.addMergedRegion(0, (short) 0, 1, (short) 1);
-			
-		int records = sheet.getRecords().size();
-		
-		//remove a third from the beginning
-		for (int n = 0; n < regionsToAdd/3; n++)
-		{
-			sheet.removeMergedRegion(0); 
-			//assert they have been deleted
-			assertTrue("Num of regions should be " + (regionsToAdd - n - 1) + " not " + sheet.getNumMergedRegions(),
sheet.getNumMergedRegions() == regionsToAdd - n - 1);
-		}
-		
-		//assert any record removing was done
-		int recordsRemoved = (regionsToAdd/3)/1027; //doesn't work for particular values of regionsToAdd
-		assertTrue("Expected " + recordsRemoved + " record to be removed from the starting " +
records + ".  Currently there are " + sheet.getRecords().size() + " records", records - sheet.getRecords().size()
== recordsRemoved);
-	}
-
-	/**
-	 * Bug: 22922 (Reported by Xuemin Guan)
-	 * <p>
-	 * Remove mergedregion fails when a sheet loses records after an initial CreateSheet
-	 * fills up the records.
-	 *
-	 */
-	public void testMovingMergedRegion() {
-		List records = new ArrayList();
-		
-		MergeCellsRecord merged = new MergeCellsRecord();
-		merged.addArea(0, (short)0, 1, (short)2);
-		records.add(new RowRecord());
-		records.add(new RowRecord());
-		records.add(new RowRecord());
-		records.add(merged);
-		
-		Sheet sheet = Sheet.createSheet(records, 0);
-		sheet.records.remove(0);
-		
-		//stub object to throw off list INDEX operations
-		sheet.removeMergedRegion(0);
-		assertEquals("Should be no more merged regions", 0, sheet.getNumMergedRegions());
-	}
-
-	public void testGetMergedRegionAt()
-	{
-		//TODO
-	}
-
-	public void testGetNumMergedRegions()
-	{
-		//TODO
-	}
-
-	public void DISBALEDtestGetCellWidth() throws Exception
-	{
+	public void testGetCellWidth() {
 		Sheet sheet = Sheet.createSheet();
 		ColumnInfoRecord nci = ( ColumnInfoRecord ) sheet.createColInfo();
 
@@ -146,14 +39,8 @@
 		nci.setLastColumn((short)10);
 		nci.setColumnWidth((short)100);
 		
-		Field f = null;
-		f = Sheet.class.getDeclaredField("columnSizes");
-		f.setAccessible(true);
-		List columnSizes = new ArrayList();
-		f.set(sheet,columnSizes);
-		columnSizes.add(nci);
-		sheet.records.add(1 + sheet.dimsloc, nci);
-		sheet.dimsloc++;
+		
+		sheet.columns.insertColumn(nci);
 
 		assertEquals((short)100,sheet.getColumnWidth((short)5));
 		assertEquals((short)100,sheet.getColumnWidth((short)6));
@@ -172,151 +59,6 @@
 		assertEquals((short)100,sheet.getColumnWidth((short)10));
 	}
 
-	/**
-	 * Makes sure all rows registered for this sheet are aggregated, they were being skipped
-	 *
-	 */
-	public void testRowAggregation() {
-		List records = new ArrayList();
-		RowRecord row = new RowRecord();
-		row.setRowNumber(0);		
-		records.add(row);
-		
-		row = new RowRecord();
-		row.setRowNumber(1);
-		records.add(row);
-
-		records.add(new StringRecord());
-		
-		row = new RowRecord();
-		row.setRowNumber(2);
-		records.add(row);
-		
-		
-		Sheet sheet = Sheet.createSheet(records, 0);
-		assertNotNull("Row [2] was skipped", sheet.getRow(2));
-		
-	}
-	
-	/**
-	 * Make sure page break functionality works (in memory)
-	 *
-	 */
-	public void testRowPageBreaks(){
-		short colFrom = 0;
-		short colTo = 255;
-		
-		Sheet sheet = Sheet.createSheet();
-		sheet.setRowBreak(0, colFrom, colTo);
-		
-		assertTrue("no row break at 0", sheet.isRowBroken(0));
-		assertEquals("1 row break available", 1, sheet.getNumRowBreaks());
-		
-		sheet.setRowBreak(0, colFrom, colTo);		
-		sheet.setRowBreak(0, colFrom, colTo);		
-
-		assertTrue("no row break at 0", sheet.isRowBroken(0));
-		assertEquals("1 row break available", 1, sheet.getNumRowBreaks());
-		
-		sheet.setRowBreak(10, colFrom, colTo);
-		sheet.setRowBreak(11, colFrom, colTo);
-
-		assertTrue("no row break at 10", sheet.isRowBroken(10));
-		assertTrue("no row break at 11", sheet.isRowBroken(11));
-		assertEquals("3 row break available", 3, sheet.getNumRowBreaks());
-		
-		
-		boolean is10 = false;
-		boolean is0 = false;
-		boolean is11 = false;
-		
-		Iterator iterator = sheet.getRowBreaks();
-		while (iterator.hasNext()) {
-			PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-			int main = (int)breakItem.main;
-			if (main != 0 && main != 10 && main != 11) fail("Invalid page break");
-			if (main == 0) 	is0 = true;
-			if (main == 10) is10= true;
-			if (main == 11) is11 = true;
-		}
-		
-		assertTrue("one of the breaks didnt make it", is0 && is10 && is11); 
-		
-		sheet.removeRowBreak(11);
-		assertFalse("row should be removed", sheet.isRowBroken(11));
-		
-		sheet.removeRowBreak(0);
-		assertFalse("row should be removed", sheet.isRowBroken(0));
-		
-		sheet.removeRowBreak(10);
-		assertFalse("row should be removed", sheet.isRowBroken(10));
-		
-		assertEquals("no more breaks", 0, sheet.getNumRowBreaks());
-		
-		
-	}
-	
-	/**
-	 * Make sure column pag breaks works properly (in-memory)
-	 *
-	 */
-	public void testColPageBreaks(){
-		short rowFrom = 0;
-		short rowTo = (short)65535;
-		
-		Sheet sheet = Sheet.createSheet();
-		sheet.setColumnBreak((short)0, rowFrom, rowTo); 
-		
-		assertTrue("no col break at 0", sheet.isColumnBroken((short)0));
-		assertEquals("1 col break available", 1, sheet.getNumColumnBreaks());		
-		
-		sheet.setColumnBreak((short)0, rowFrom, rowTo);
-		
-		assertTrue("no col break at 0", sheet.isColumnBroken((short)0));
-		assertEquals("1 col break available", 1, sheet.getNumColumnBreaks());		
-		
-		sheet.setColumnBreak((short)1, rowFrom, rowTo);
-		sheet.setColumnBreak((short)10, rowFrom, rowTo);
-		sheet.setColumnBreak((short)15, rowFrom, rowTo);
-		
-		assertTrue("no col break at 1", sheet.isColumnBroken((short)1));
-		assertTrue("no col break at 10", sheet.isColumnBroken((short)10));
-		assertTrue("no col break at 15", sheet.isColumnBroken((short)15));
-		assertEquals("4 col break available", 4, sheet.getNumColumnBreaks());		
-
-		boolean is10 = false;
-		boolean is0 = false;
-		boolean is1 = false;
-		boolean is15 = false;
-		
-		Iterator iterator = sheet.getColumnBreaks();
-		while (iterator.hasNext()) {
-			PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-			int main = (int)breakItem.main;
-			if (main != 0 && main != 1 && main != 10 && main != 15) fail("Invalid
page break");
-			if (main == 0) 	is0 = true;
-			if (main == 1) 	is1 = true;
-			if (main == 10) is10= true;
-			if (main == 15) is15 = true;
-		}
-		
-		assertTrue("one of the breaks didnt make it", is0 && is1 && is10 &&
is15); 
-		
-		sheet.removeColumnBreak((short)15);
-		assertFalse("column break should not be there", sheet.isColumnBroken((short)15));
-
-		sheet.removeColumnBreak((short)0);
-		assertFalse("column break should not be there", sheet.isColumnBroken((short)0));
-		
-		sheet.removeColumnBreak((short)1);
-		assertFalse("column break should not be there", sheet.isColumnBroken((short)1));
-		
-		sheet.removeColumnBreak((short)10);
-		assertFalse("column break should not be there", sheet.isColumnBroken((short)10));
-		
-		assertEquals("no more breaks", 0, sheet.getNumColumnBreaks());
-	}
-
 }
 
 

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java?rev=655278&r1=655277&r2=655278&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java
Sun May 11 01:15:39 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,34 +14,28 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
+
 package org.apache.poi.hssf.record.aggregates;
 
-import org.apache.poi.hssf.record.*;
+import junit.framework.TestCase;
 
-public class TestRowRecordsAggregate extends junit.framework.TestCase {
-    public TestRowRecordsAggregate(String name) {
-        super (name);
-    }
+import org.apache.poi.hssf.record.RowRecord;
+
+/**
+ * 
+ */
+public final class TestRowRecordsAggregate extends TestCase {
     
     public void testRowGet() {
         RowRecordsAggregate rra = new RowRecordsAggregate();
-        RowRecord rr = new RowRecord();
-        rr.setRowNumber(( short ) 4);
+        RowRecord rr = new RowRecord(4);
         rra.insertRow(rr);
-        RowRecord rr2 = new RowRecord(); rr2.setRowNumber((short) 1);
-        rra.insertRow(rr2);
+        rra.insertRow(new RowRecord(1));
         
         RowRecord rr1 = rra.getRow(4);
         
-        assertTrue("Row Record should not be null", rr1!=null);
-        assertTrue("Row number is 1",rr1.getRowNumber() == 4);
+        assertNotNull(rr1);
+        assertEquals("Row number is 1", 4, rr1.getRowNumber());
         assertTrue("Row record retrieved is identical ", rr1 == rr);
     }
-    
-     public static void main(String [] args) {
-        System.out
-        .println("Testing org.apache.poi.hssf.record.aggregates.RowRecordAggregate");
-        junit.textui.TestRunner.run(TestRowRecordsAggregate.class);
-    }
 }

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=655278&r1=655277&r2=655278&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 Sun May 11 01:15:39
2008
@@ -143,8 +143,9 @@
       try {
         sheet.createRow(-1);
         fail("IndexOutOfBoundsException should have been thrown");
-      } catch (IndexOutOfBoundsException ex) {
+      } catch (IllegalArgumentException e) {
         // expected during successful test
+        assertEquals("Invalid row number (-1) outside allowable range (0..65535)", e.getMessage());
       }
 
       //Test high row bound
@@ -153,8 +154,9 @@
       try {
         sheet.createRow(65536);
         fail("IndexOutOfBoundsException should have been thrown");
-      } catch (IndexOutOfBoundsException ex) {
+      } catch (IllegalArgumentException e) {
         // expected during successful test
+        assertEquals("Invalid row number (65536) outside allowable range (0..65535)", e.getMessage());
       }
     }
 

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=655278&r1=655277&r2=655278&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 Sun May 11 01:15:39
2008
@@ -23,6 +23,7 @@
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
@@ -193,17 +194,29 @@
 	public void testCloneSheet() {
 		HSSFWorkbook workbook = new HSSFWorkbook();
 		HSSFSheet sheet = workbook.createSheet("Test Clone");
-		HSSFRow row = sheet.createRow((short) 0);
+		HSSFRow row = sheet.createRow(0);
 		HSSFCell cell = row.createCell((short) 0);
-		cell.setCellValue("clone_test"); 
-		HSSFSheet cloned = workbook.cloneSheet(0);
-  
+		HSSFCell cell2 = row.createCell((short) 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(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), "clone_test");
+		assertEquals(clonedRow.getCell(0).getRichStringCellValue().getString(), "clone_test");
 
 		//Check that the cells are not somehow linked
-		cell.setCellValue("Difference Check");
-		assertEquals(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), "clone_test");
+		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
@@ -214,7 +227,7 @@
 		HSSFSheet sheet = workbook.createSheet("Test Clone");
 		HSSFRow row = sheet.createRow((short) 0);
 		HSSFCell cell = row.createCell((short) 0);
-		cell.setCellValue("clone_test");
+		cell.setCellValue(new HSSFRichTextString("clone_test"));
 		//Clone the sheet multiple times
 		workbook.cloneSheet(0);
 		workbook.cloneSheet(0);
@@ -517,11 +530,11 @@
 		HSSFSheet sheet = wb.createSheet();
 		HSSFRow row = sheet.createRow(0);
 		HSSFCell cell = row.createCell((short)0);
-		cell.setCellValue("first row, first cell");
+		cell.setCellValue(new HSSFRichTextString("first row, first cell"));
 
 		row = sheet.createRow(1);
 		cell = row.createCell((short)1);
-		cell.setCellValue("second row, second cell");
+		cell.setCellValue(new HSSFRichTextString("second row, second cell"));
 
 		Region region = new Region(1, (short)0, 1, (short)1);   
 		sheet.addMergedRegion(region);
@@ -643,28 +656,28 @@
 
 	/** cell with formula becomes null on cloning a sheet*/
 	 public void test35084() {
-   
-   	HSSFWorkbook wb = new HSSFWorkbook();
-   	HSSFSheet s =wb.createSheet("Sheet1");
-   	HSSFRow r = s.createRow(0);
-   	r.createCell((short)0).setCellValue(1);
-   	r.createCell((short)1).setCellFormula("A1*2");
-   	HSSFSheet s1 = wb.cloneSheet(0);
-   	r=s1.getRow(0);
-   	assertEquals("double" ,r.getCell((short)0).getNumericCellValue(),(double)1,0); //sanity
check
-   	assertNotNull(r.getCell((short)1)); 
-   	assertEquals("formula", r.getCell((short)1).getCellFormula(), "A1*2");
-   }
+
+		HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFSheet s = wb.createSheet("Sheet1");
+		HSSFRow r = s.createRow(0);
+		r.createCell((short) 0).setCellValue(1);
+		r.createCell((short) 1).setCellFormula("A1*2");
+		HSSFSheet s1 = wb.cloneSheet(0);
+		r = s1.getRow(0);
+		assertEquals("double", r.getCell((short) 0).getNumericCellValue(), 1, 0); // sanity check
+		assertNotNull(r.getCell((short) 1));
+		assertEquals("formula", r.getCell((short) 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((short)0);
-	assertEquals("style should match", style.getIndex(), c.getCellStyle().getIndex());
+		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((short) 0);
+		assertEquals("style should match", style.getIndex(), c.getCellStyle().getIndex());
 	}
 
 
@@ -814,11 +827,6 @@
 		assertTrue(wb3.getSheetAt(3).getForceFormulaRecalculation());
 	}
 
-
-	public static void main(java.lang.String[] args) {
-		 junit.textui.TestRunner.run(TestHSSFSheet.class);
-	}
-
 	public void testColumnWidth() throws Exception {
 		//check we can correctly read column widths from a reference workbook
 		HSSFWorkbook wb = openSample("colwidth.xls");
@@ -870,11 +878,33 @@
 		assertEquals(256*10, sh.getColumnWidth((short)0));
 		assertEquals(256*10, sh.getColumnWidth((short)1));
 		assertEquals(256*10, sh.getColumnWidth((short)2));
-		//columns D-F have custom wodth
+		//columns D-F have custom width
 		for (char i = 'D'; i <= 'F'; i++) {
 			short w = (short)(256*12);
 			assertEquals(w, sh.getColumnWidth((short)i));
 		}
+	}
+	
+	/**
+	 * Some utilities write Excel files without the ROW records.
+	 * Excel, ooo, and google docs are OK with this.
+	 * Now POI is too.
+	 */
+	public void testMissingRowRecords_bug41187() {
+		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex41187-19267.xls");
 
+		HSSFSheet sheet = wb.getSheetAt(0);
+		HSSFRow row = sheet.getRow(0);
+		if(row == null) {
+			throw new AssertionFailedError("Identified bug 41187 a");
+		}
+		if (row.getHeight() == 0) {
+			throw new AssertionFailedError("Identified bug 41187 b");
+		}
+		assertEquals("Hi Excel!", row.getCell(0).getRichStringCellValue().getString());
+		// check row height for 'default' flag
+		assertEquals((short)0x8000, row.getHeight());
+		
+		HSSFTestDataSamples.writeOutAndReadBack(wb);
 	}
 }

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=655278&r1=655277&r2=655278&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 Sun May 11
01:15:39 2008
@@ -147,9 +147,10 @@
         // Single chart, two sheets
         b = openSample("44010-SingleChart.xls");
         assertEquals(2, b.getNumberOfSheets());
+        assertEquals("Graph2", b.getSheetName(1));
         s = b.getSheetAt(1);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
+        assertEquals(8, s.getLastRowNum());
         
         // Has chart on 1st sheet??
         // FIXME
@@ -166,7 +167,7 @@
         assertEquals(2, b.getNumberOfSheets());
         s = b.getSheetAt(1);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
+        assertEquals(8, s.getLastRowNum());
 
         
         // Two charts, three sheets
@@ -175,10 +176,10 @@
         
         s = b.getSheetAt(1);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
+        assertEquals(8, s.getLastRowNum());
         s = b.getSheetAt(2);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
+        assertEquals(8, s.getLastRowNum());
         
         // Has chart on 1st sheet??
         // FIXME
@@ -197,13 +198,13 @@
         
         s = b.getSheetAt(1);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
+        assertEquals(8, s.getLastRowNum());
         s = b.getSheetAt(2);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
+        assertEquals(8, s.getLastRowNum());
     }
     
     private static HSSFWorkbook writeRead(HSSFWorkbook b) {
-    	return HSSFTestDataSamples.writeOutAndReadBack(b);
+        return HSSFTestDataSamples.writeOutAndReadBack(b);
     }
 }
\ No newline at end of file



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


Mime
View raw message