poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r683670 [4/4] - in /poi/branches/ooxml: ./ src/java/org/apache/poi/hssf/dev/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/ src/java/org/apache/poi/hssf/record/aggregates/ src/java/org/apache/poi/hssf/record/formul...
Date Thu, 07 Aug 2008 18:21:34 GMT
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheet.java?rev=683670&r1=683669&r2=683670&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheet.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheet.java Thu Aug  7 11:21:32
2008
@@ -17,20 +17,31 @@
 
 package org.apache.poi.hssf.model;
 
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.List;
+
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.eventmodel.ERFListener;
 import org.apache.poi.hssf.eventmodel.EventRecordFactory;
-import org.apache.poi.hssf.record.*;
+import org.apache.poi.hssf.record.BOFRecord;
+import org.apache.poi.hssf.record.BlankRecord;
+import org.apache.poi.hssf.record.CellValueRecordInterface;
+import org.apache.poi.hssf.record.ColumnInfoRecord;
+import org.apache.poi.hssf.record.DimensionsRecord;
+import org.apache.poi.hssf.record.EOFRecord;
+import org.apache.poi.hssf.record.IndexRecord;
+import org.apache.poi.hssf.record.MergeCellsRecord;
+import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RowRecord;
+import org.apache.poi.hssf.record.StringRecord;
+import org.apache.poi.hssf.record.UncalcedRecord;
 import org.apache.poi.hssf.record.aggregates.ColumnInfoRecordsAggregate;
 import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
 import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate;
-
-import java.io.ByteArrayInputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import org.apache.poi.hssf.util.CellRangeAddress;
 
 /**
  * Unit test for the Sheet class.
@@ -55,10 +66,24 @@
         assertTrue( sheet.records.get(pos++) instanceof EOFRecord );
     }
 
+    private static final class MergedCellListener implements ERFListener {
+
+        private int _count;
+        public MergedCellListener() {
+            _count = 0;
+        }
+        public boolean processRecord(Record rec) {
+            _count++;
+            return true;
+        }
+        public int getCount() {
+            return _count;
+        }
+    }
+    
     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++)
@@ -71,11 +96,18 @@
         assertTrue(sheet.getNumMergedRegions() == regionsToAdd);
 
         //test that the regions were spread out over the appropriate number of records
-        int recordsAdded    = sheet.getRecords().size() - startRecords;
+        byte[] sheetData = new byte[sheet.getSize()];
+        sheet.serialize(0, sheetData);
+        MergedCellListener mcListener = new MergedCellListener();
+        EventRecordFactory erf = new EventRecordFactory(mcListener, new short[] { MergeCellsRecord.sid,
});
+//        POIFSFileSystem poifs = new POIFSFileSystem(new ByteArrayInputStream(sheetData));
+        erf.processRecords(new ByteArrayInputStream(sheetData));
+        int recordsAdded    = mcListener.getCount();
         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);
+        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);
@@ -97,22 +129,23 @@
         Sheet sheet = Sheet.createSheet();
         int regionsToAdd = 4096;
 
-        for (int n = 0; n < regionsToAdd; n++)
-            sheet.addMergedRegion(0, (short) 0, 1, (short) 1);
+        for (int n = 0; n < regionsToAdd; n++) {
+            sheet.addMergedRegion(n, 0, n, 1);
+        }
 
-        int records = sheet.getRecords().size();
+        int nSheetRecords = 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);
+            assertEquals("Num of regions", regionsToAdd - n - 1, sheet.getNumMergedRegions());
         }
-
-        //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);
+        
+        // merge records are removed from within the MergedCellsTable, 
+        // so the sheet record count should not change 
+        assertEquals("Sheet Records", nSheetRecords, sheet.getRecords().size());
     }
 
     /**
@@ -125,8 +158,11 @@
     public void testMovingMergedRegion() {
         List records = new ArrayList();
 
-        MergeCellsRecord merged = new MergeCellsRecord();
-        merged.addArea(0, (short)0, 1, (short)2);
+        CellRangeAddress[] cras = {
+            new CellRangeAddress(0, 1, 0, 2),
+        };
+        MergeCellsRecord merged = new MergeCellsRecord(cras, 0, cras.length);
+        records.add(new DimensionsRecord());
         records.add(new RowRecord(0));
         records.add(new RowRecord(1));
         records.add(new RowRecord(2));
@@ -155,6 +191,7 @@
     public void testRowAggregation() {
         List records = new ArrayList();
 
+        records.add(new DimensionsRecord());
         records.add(new RowRecord(0));
         records.add(new RowRecord(1));
         records.add(new StringRecord());
@@ -196,10 +233,9 @@
         boolean is0 = false;
         boolean is11 = false;
 
-        Iterator iterator = sheet.getRowBreaks();
-        while (iterator.hasNext()) {
-            PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-            int main = breakItem.main;
+        int[] rowBreaks = sheet.getRowBreaks();
+        for (int i = 0; i < rowBreaks.length; i++) {
+            int main = rowBreaks[i];
             if (main != 0 && main != 10 && main != 11) fail("Invalid page
break");
             if (main == 0)     is0 = true;
             if (main == 10) is10= true;
@@ -253,10 +289,9 @@
         boolean is1 = false;
         boolean is15 = false;
 
-        Iterator iterator = sheet.getColumnBreaks();
-        while (iterator.hasNext()) {
-            PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-            int main = breakItem.main;
+        int[] colBreaks = sheet.getColumnBreaks();
+        for (int i = 0; i < colBreaks.length; i++) {
+            int main = colBreaks[i];
             if (main != 0 && main != 1 && main != 10 && main != 15)
fail("Invalid page break");
             if (main == 0)  is0 = true;
             if (main == 1)  is1 = true;
@@ -297,9 +332,8 @@
         xfindex = sheet.getXFIndexForColAt((short) 1);
         assertEquals(DEFAULT_IDX, xfindex);
 
-        // TODO change return type to ColumnInfoRecord 
-        ColumnInfoRecord nci = (ColumnInfoRecord)ColumnInfoRecordsAggregate.createColInfo();
-        sheet.columns.insertColumn(nci);
+        ColumnInfoRecord nci = ColumnInfoRecordsAggregate.createColInfo();
+        sheet._columnInfos.insertColumn(nci);
 
         // single column ColumnInfoRecord
         nci.setFirstColumn((short) 2);
@@ -361,6 +395,7 @@
         List records = new ArrayList();
         records.add(new BOFRecord());
         records.add(new UncalcedRecord());
+        records.add(new DimensionsRecord());
         records.add(new EOFRecord());
         Sheet sheet = Sheet.createSheet(records, 0, 0);
 
@@ -369,7 +404,7 @@
         if (serializedSize != estimatedSize) {
             throw new AssertionFailedError("Identified bug 45066 b");
         }
-        assertEquals(50, serializedSize);
+        assertEquals(68, serializedSize);
     }
 
     /**
@@ -393,7 +428,7 @@
 
 
         int dbCellRecordPos = getDbCellRecordPos(sheet);
-        if (dbCellRecordPos == 264) {
+        if (dbCellRecordPos == 252) {
             // The overt symptom of the bug
             // DBCELL record pos is calculated wrong if VRA comes before RRA
             throw new AssertionFailedError("Identified  bug 45145");
@@ -405,7 +440,7 @@
         assertEquals(RowRecordsAggregate.class, recs.get(rraIx).getClass());
         assertEquals(ValueRecordsAggregate.class, recs.get(rraIx+1).getClass());
 
-        assertEquals(254, dbCellRecordPos);
+        assertEquals(242, dbCellRecordPos);
     }
 
     /**

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java?rev=683670&r1=683669&r2=683670&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java Thu
Aug  7 11:21:32 2008
@@ -29,8 +29,7 @@
 	
 	public void testGetCellWidth() {
 		Sheet sheet = Sheet.createSheet();
-		// TODO change return type to ColumnInfoRecord 
-		ColumnInfoRecord nci = (ColumnInfoRecord)ColumnInfoRecordsAggregate.createColInfo();
+		ColumnInfoRecord nci = ColumnInfoRecordsAggregate.createColInfo();
 
 		// Prepare test model
 		nci.setFirstColumn((short)5);
@@ -38,7 +37,7 @@
 		nci.setColumnWidth((short)100);
 		
 		
-		sheet.columns.insertColumn(nci);
+		sheet._columnInfos.insertColumn(nci);
 
 		assertEquals((short)100,sheet.getColumnWidth((short)5));
 		assertEquals((short)100,sheet.getColumnWidth((short)6));
@@ -58,6 +57,3 @@
 	}
 
 }
-
-
-

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java?rev=683670&r1=683669&r2=683670&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java
Thu Aug  7 11:21:32 2008
@@ -33,8 +33,8 @@
     * @throws Exception
     */
    public void testCloneReferences() throws Exception {
-      MergeCellsRecord merge = new MergeCellsRecord();
-      merge.addArea(0, (short)0, 1, (short)2);
+      CellRangeAddress[] cras = { new CellRangeAddress(0, 1, 0, 2), };
+      MergeCellsRecord merge = new MergeCellsRecord(cras, 0, cras.length);
       MergeCellsRecord clone = (MergeCellsRecord)merge.clone();
       
       assertNotSame("Merged and cloned objects are the same", merge, clone);
@@ -47,7 +47,6 @@
       assertEquals("New Clone Col From doesnt match", mergeRegion.getFirstColumn(), cloneRegion.getFirstColumn());
       assertEquals("New Clone Col To doesnt match", mergeRegion.getLastColumn(), cloneRegion.getLastColumn());
     
       
-      merge.removeAreaAt(0);
-      assertNotNull("Clone's item not removed", clone.getAreaAt(0));
+      assertFalse(merge.getAreaAt(0) == clone.getAreaAt(0));
    }
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java?rev=683670&r1=683669&r2=683670&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java
Thu Aug  7 11:21:32 2008
@@ -24,6 +24,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.model.RecordStream;
 import org.apache.poi.hssf.record.CFHeaderRecord;
 import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.RecordFactory;
@@ -59,7 +60,7 @@
 		recs.add(rule2);
 		recs.add(rule3);
 		CFRecordsAggregate record;
-		record = CFRecordsAggregate.createCFAggregate(recs, 0);
+		record = CFRecordsAggregate.createCFAggregate(new RecordStream(recs, 0));
 
 		// Serialize
 		byte [] serializedRecord = record.serialize();
@@ -81,7 +82,7 @@
 		assertEquals(2, cellRanges.length);
 		assertEquals(3, header.getNumberOfConditionalFormats());
 
-		record = CFRecordsAggregate.createCFAggregate(recs, 0);
+		record = CFRecordsAggregate.createCFAggregate(new RecordStream(recs, 0));
 
 		record = record.cloneCFAggregate();
 

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java?rev=683670&r1=683669&r2=683670&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java
Thu Aug  7 11:21:32 2008
@@ -19,42 +19,39 @@
 
 import junit.framework.TestCase;
 import org.apache.poi.hssf.record.ColumnInfoRecord;
+import org.apache.poi.hssf.record.RecordBase;
 
 /**
  * @author Glen Stampoultzis
  */
-public final class TestColumnInfoRecordsAggregate extends TestCase
-{
-    ColumnInfoRecordsAggregate columnInfoRecordsAggregate;
-
-    public void testGetRecordSize() throws Exception
-    {
-        columnInfoRecordsAggregate = new ColumnInfoRecordsAggregate();
-        columnInfoRecordsAggregate.insertColumn( createColumn( (short)1, (short)3 ));
-        columnInfoRecordsAggregate.insertColumn( createColumn( (short)4, (short)7 ));
-        columnInfoRecordsAggregate.insertColumn( createColumn( (short)8, (short)8 ));
-//        columnInfoRecordsAggregate.setColumn( (short)2, new Short( (short)200 ), new Integer(
1 ), new Boolean( true ), null);
-        columnInfoRecordsAggregate.groupColumnRange( (short)2, (short)5, true );
-        assertEquals(6, columnInfoRecordsAggregate.getNumColumns());
-
-        assertEquals(columnInfoRecordsAggregate.getRecordSize(), columnInfoRecordsAggregate.serialize().length);
-
-        columnInfoRecordsAggregate = new ColumnInfoRecordsAggregate();
-        columnInfoRecordsAggregate.groupColumnRange( (short)3, (short)6, true );
-
-        assertEquals(columnInfoRecordsAggregate.getRecordSize(), serializedSize());
-    }
-
-    private int serializedSize()
-    {
-        return columnInfoRecordsAggregate.serialize(0, new byte[columnInfoRecordsAggregate.getRecordSize()]);
-    }
-
-    private ColumnInfoRecord createColumn( short firstCol, short lastCol )
-    {
-        ColumnInfoRecord columnInfoRecord = new ColumnInfoRecord( );
-        columnInfoRecord.setFirstColumn(firstCol);
-        columnInfoRecord.setLastColumn(lastCol);
-        return columnInfoRecord;
-    }
+public final class TestColumnInfoRecordsAggregate extends TestCase {
+
+	public void testGetRecordSize() {
+		ColumnInfoRecordsAggregate agg = new ColumnInfoRecordsAggregate();
+		agg.insertColumn(createColumn(1, 3));
+		agg.insertColumn(createColumn(4, 7));
+		agg.insertColumn(createColumn(8, 8));
+		agg.groupColumnRange((short) 2, (short) 5, true);
+		assertEquals(6, agg.getNumColumns());
+
+		confirmSerializedSize(agg);
+
+		agg = new ColumnInfoRecordsAggregate();
+		agg.groupColumnRange((short) 3, (short) 6, true);
+		confirmSerializedSize(agg);
+	}
+
+	private static void confirmSerializedSize(RecordBase cirAgg) {
+		int estimatedSize = cirAgg.getRecordSize();
+		byte[] buf = new byte[estimatedSize];
+		int serializedSize = cirAgg.serialize(0, buf);
+		assertEquals(estimatedSize, serializedSize);
+	}
+
+	private static ColumnInfoRecord createColumn(int firstCol, int lastCol) {
+		ColumnInfoRecord columnInfoRecord = new ColumnInfoRecord();
+		columnInfoRecord.setFirstColumn((short) firstCol);
+		columnInfoRecord.setLastColumn((short) lastCol);
+		return columnInfoRecord;
+	}
 }
\ No newline at end of file

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=683670&r1=683669&r2=683670&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Thu Aug 
7 11:21:32 2008
@@ -660,7 +660,7 @@
 
             HSSFSheet sheet = wb.getSheetAt( 0 );
             int[] breaks = sheet.getRowBreaks();
-            assertNull(breaks);
+            assertEquals(0, breaks.length);
 
             //add 3 row breaks
             for (int j = 1; j <= 3; j++) {



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


Mime
View raw message