You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/08/28 15:26:14 UTC

svn commit: r689811 [2/2] - in /poi/branches/ooxml: ./ src/documentation/content/xdocs/ 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/formula...

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java?rev=689811&r1=689810&r2=689811&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java Thu Aug 28 06:26:12 2008
@@ -26,8 +26,10 @@
 import org.apache.poi.hssf.record.CellValueRecordInterface;
 import org.apache.poi.hssf.record.DBCellRecord;
 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.UnknownRecord;
 
 /**
  *
@@ -39,6 +41,7 @@
     private int _lastrow  = -1;
     private final Map _rowRecords;
     private final ValueRecordsAggregate _valuesAgg;
+    private final List _unknownRecords;
 
     /** Creates a new instance of ValueRecordsAggregate */
 
@@ -48,8 +51,54 @@
     private RowRecordsAggregate(TreeMap rowRecords, ValueRecordsAggregate valuesAgg) {
         _rowRecords = rowRecords;
         _valuesAgg = valuesAgg;
+        _unknownRecords = new ArrayList();
     }
 
+    public RowRecordsAggregate(List recs, int startIx, int endIx) {
+        this();
+        // First up, locate all the shared formulas for this sheet
+        SharedFormulaHolder sfh = SharedFormulaHolder.create(recs, startIx, endIx);
+        for(int i=startIx; i<endIx; i++) {
+            Record rec = (Record) recs.get(i);
+            switch (rec.getSid()) {
+                case MergeCellsRecord.sid:
+                    // Some apps scatter these records between the rows/cells but they are supposed to
+                    // be well after the row/cell records.  It is assumed such rogue MergeCellRecords 
+                    // have already been collected by the caller, and can safely be ignored here. 
+                    // see bug 45699
+                    continue;
+                case RowRecord.sid:
+                    insertRow((RowRecord) rec);
+                    continue;
+                case DBCellRecord.sid:
+                    // end of 'Row Block'.  Should only occur after cell records
+                    continue;
+            }
+            if (rec instanceof UnknownRecord) {
+                addUnknownRecord((UnknownRecord)rec);
+                // might need to keep track of where exactly these belong
+                continue;
+            }
+            if (!rec.isValue()) {
+                throw new RuntimeException("Unexpected record type (" + rec.getClass().getName() + ")");
+            }
+            i += _valuesAgg.construct(recs, i, endIx, sfh);
+        }
+        "".length();
+    }
+    /**
+     * Handles UnknownRecords which appear within the row/cell records
+     */
+    private void addUnknownRecord(UnknownRecord rec) {
+        // ony a few distinct record IDs are encountered by the existing POI test cases:
+        // 0x1065 // many
+        // 0x01C2 // several
+        // 0x0034 // few
+        // No documentation could be found for these
+        
+        // keep the unknown records for re-serialization
+        _unknownRecords.add(rec);
+    }
     public void insertRow(RowRecord row) {
         // Integer integer = new Integer(row.getRowNumber());
         _rowRecords.put(new Integer(row.getRowNumber()), row);
@@ -215,6 +264,10 @@
             cellRecord.setRowOffset(pos);
             rv.visitRecord(cellRecord);
         }
+        for (int i=0; i< _unknownRecords.size(); i++) {
+            // Potentially breaking the file here since we don't know exactly where to write these records
+            rv.visitRecord((Record) _unknownRecords.get(i));
+        }
     }
 
     public Iterator getIterator() {
@@ -439,9 +492,6 @@
         }
         return result;
     }
-    public void constructCellValues(int offset, List records) {
-        _valuesAgg.construct(offset, records);
-    }
     public void insertCell(CellValueRecordInterface cvRec) {
         _valuesAgg.insertCell(cvRec);
     }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java?rev=689811&r1=689810&r2=689811&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java Thu Aug 28 06:26:12 2008
@@ -22,11 +22,15 @@
 import java.util.List;
 
 import org.apache.poi.hssf.record.CellValueRecordInterface;
-import org.apache.poi.hssf.record.EOFRecord;
+import org.apache.poi.hssf.record.DBCellRecord;
 import org.apache.poi.hssf.record.FormulaRecord;
+import org.apache.poi.hssf.record.MergeCellsRecord;
 import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RecordBase;
+import org.apache.poi.hssf.record.RowRecord;
 import org.apache.poi.hssf.record.SharedFormulaRecord;
 import org.apache.poi.hssf.record.StringRecord;
+import org.apache.poi.hssf.record.TableRecord;
 import org.apache.poi.hssf.record.UnknownRecord;
 import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
 
@@ -39,8 +43,8 @@
  * @author Jason Height (jheight at chariot dot net dot au)
  */
 public final class ValueRecordsAggregate {
-    private int                       firstcell = -1;
-    private int                       lastcell  = -1;
+    private int firstcell = -1;
+    private int lastcell  = -1;
     private CellValueRecordInterface[][] records;
 
     /** Creates a new instance of ValueRecordsAggregate */
@@ -137,92 +141,81 @@
         return lastcell;
     }
 
-    public int construct(int offset, List records)
-    {
+    /**
+     * Processes a sequential group of cell value records.  Stops at endIx or the first 
+     * non-value record encountered.
+     * @param sfh used to resolve any shared formulas for the current sheet
+     * @return the number of records consumed
+     */
+    public int construct(List records, int offset, int endIx, SharedFormulaHolder sfh) {
         int k = 0;
 
         FormulaRecordAggregate lastFormulaAggregate = null;
         
-        // First up, locate all the shared formulas for this sheet
-        List sharedFormulas = new java.util.ArrayList();
-        for (k = offset; k < records.size(); k++)
-        {
+        // Now do the main processing sweep
+        for (k = offset; k < endIx; k++) {
             Record rec = ( Record ) records.get(k);
+
+            if (rec instanceof StringRecord) {
+                if (lastFormulaAggregate == null) {
+                    throw new RuntimeException("StringRecord found without preceding FormulaRecord");
+                }
+                if (lastFormulaAggregate.getStringRecord() != null) {
+                    throw new RuntimeException("Multiple StringRecords found after FormulaRecord");
+                }
+                lastFormulaAggregate.setStringRecord((StringRecord)rec);
+                lastFormulaAggregate = null;
+                continue;
+            }
+            
+            if (rec instanceof TableRecord) {
+                // TODO - don't loose this record
+                // DATATABLE probably belongs in formula record aggregate
+                if (lastFormulaAggregate == null) {
+                    throw new RuntimeException("No preceding formula record found");
+                }
+                lastFormulaAggregate = null;
+                continue; 
+            }
+            
             if (rec instanceof SharedFormulaRecord) {
-                sharedFormulas.add(rec);
+                // Already handled, not to worry
+                continue;
             }
-            if(rec instanceof EOFRecord) {
-                // End of current sheet. Ignore all subsequent shared formula records (Bugzilla 44449)
+
+            if (rec instanceof UnknownRecord) {
                 break;
             }
-        }
-
-        // Now do the main processing sweep
-        for (k = offset; k < records.size(); k++)
-        {
-            Record rec = ( Record ) records.get(k);
-
-            if (rec instanceof StringRecord == false && !rec.isInValueSection() && !(rec instanceof UnknownRecord))
-            {
+            if (rec instanceof RowRecord) {
+                break; 
+            }
+            if (rec instanceof DBCellRecord) {
+                // end of 'Row Block'.  This record is ignored by POI
                 break;
-            } else if (rec instanceof SharedFormulaRecord) {
-                // Already handled, not to worry
-            } else if (rec instanceof FormulaRecord)
-            {
-              FormulaRecord formula = (FormulaRecord)rec;
-              if (formula.isSharedFormula()) {
-                // Traverse the list of shared formulas in
-                //  reverse order, and try to find the correct one
-                //  for us
-                boolean found = false;
-                for (int i=sharedFormulas.size()-1;i>=0;i--) {
-                    // TODO - there is no junit test case to justify this reversed loop
-                    // perhaps it could just run in the normal direction?
-                    SharedFormulaRecord shrd = (SharedFormulaRecord)sharedFormulas.get(i);
-                    if (shrd.isFormulaInShared(formula)) {
-                        shrd.convertSharedFormulaRecord(formula);
-                        found = true;
-                        break;
-                    }
-                }
-                if (!found) {
-                    handleMissingSharedFormulaRecord(formula);
-                }
-              }
-                
-              lastFormulaAggregate = new FormulaRecordAggregate((FormulaRecord)rec, null);
-              insertCell( lastFormulaAggregate );
             }
-            else if (rec instanceof StringRecord)
-            {
-                lastFormulaAggregate.setStringRecord((StringRecord)rec);
+            if (rec instanceof MergeCellsRecord) {
+                // doesn't really belong here
+                // can safely be ignored, because it has been processed in a higher method
+                continue;
+            }
+            if (!rec.isValue()) {
+                throw new RuntimeException("bad record type");
             }
-            else if (rec.isValue())
-            {
-                insertCell(( CellValueRecordInterface ) rec);
+            if (rec instanceof FormulaRecord) {
+                FormulaRecord formula = (FormulaRecord)rec;
+                if (formula.isSharedFormula()) {
+                    sfh.convertSharedFormulaRecord(formula);
+                }
+                
+                lastFormulaAggregate = new FormulaRecordAggregate((FormulaRecord)rec, null);
+                insertCell( lastFormulaAggregate );
+                continue;
             }
+            insertCell(( CellValueRecordInterface ) rec);
         }
-        return k;
+        return k - offset - 1;
     }
 
-    /**
-     * Sometimes the shared formula flag "seems" to be erroneously set, in which case there is no 
-     * call to <tt>SharedFormulaRecord.convertSharedFormulaRecord</tt> and hence the 
-     * <tt>parsedExpression</tt> field of this <tt>FormulaRecord</tt> will not get updated.<br/>
-     * As it turns out, this is not a problem, because in these circumstances, the existing value
-     * for <tt>parsedExpression</tt> is perfectly OK.<p/>
-     * 
-     * This method may also be used for setting breakpoints to help diagnose issues regarding the
-     * abnormally-set 'shared formula' flags. 
-     * (see TestValueRecordsAggregate.testSpuriousSharedFormulaFlag()).<p/>
-     * 
-     * The method currently does nothing but do not delete it without finding a nice home for this 
-     * comment.
-     */
-    private static void handleMissingSharedFormulaRecord(FormulaRecord formula) {
-        // could log an info message here since this is a fairly unusual occurrence.
-    }
-    
     /** Tallies a count of the size of the cell records
      *  that are attached to the rows in the range specified.
      */
@@ -235,7 +228,7 @@
         if (row > endRow)
           break;
         if ((row >=startRow) && (row <= endRow))
-          size += ((Record)cell).getRecordSize();
+          size += ((RecordBase)cell).getRecordSize();
       }
       return size;
     }
@@ -263,7 +256,7 @@
             CellValueRecordInterface cell = (CellValueRecordInterface)itr.next();
             if (cell.getRow() != row)
               break;
-            pos += (( Record ) cell).serialize(pos, data);
+            pos += (( RecordBase ) cell).serialize(pos, data);
         }
         return pos - offset;
     }
@@ -321,16 +314,6 @@
     {
     return new MyIterator();
     }
-
-    /** Performs a deep clone of the record*/
-    public Object clone() {
-      ValueRecordsAggregate rec = new ValueRecordsAggregate();
-      for (Iterator valIter = getIterator(); valIter.hasNext();) {
-        CellValueRecordInterface val = (CellValueRecordInterface)((CellValueRecordInterface)valIter.next()).clone();
-        rec.insertCell(val);
-      }
-      return rec;
-    }
   
   private final class MyIterator implements Iterator {
     short nextColumn=-1;

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/TblPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/TblPtg.java?rev=689811&r1=689810&r2=689811&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/TblPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/TblPtg.java Thu Aug 28 06:26:12 2008
@@ -25,63 +25,59 @@
 
 /**
  * This ptg indicates a data table.
- * It only occurs in a FORMULA record, never in an 
- *  ARRAY or NAME record.  When ptgTbl occurs in a 
- *  formula, it is the only token in the formula.  
- * (TODO - check this when processing)
- * This indicates that the cell containing the 
- *  formula is an interior cell in a data table; 
+ * It only occurs in a FORMULA record, never in an
+ *  ARRAY or NAME record.  When ptgTbl occurs in a
+ *  formula, it is the only token in the formula.
+ *
+ * This indicates that the cell containing the
+ *  formula is an interior cell in a data table;
  *  the table description is found in a TABLE
- *  record. Rows and columns which contain input 
- *  values to be substituted in the table do 
+ *  record. Rows and columns which contain input
+ *  values to be substituted in the table do
  *  not contain ptgTbl.
  * See page 811 of the june 08 binary docs.
  */
 public final class TblPtg extends ControlPtg {
-    private final static int  SIZE = 4;
-    public final static short sid  = 0x2;
+    private final static int  SIZE = 5;
+    public final static short sid  = 0x02;
     /** The row number of the upper left corner */
-    private final short     field_1_first_row;
+    private final int field_1_first_row;
     /** The column number of the upper left corner */
-    private final short     field_2_first_col;
+    private final int field_2_first_col;
 
-    public TblPtg(RecordInputStream in)
-    {
-      field_1_first_row = in.readShort();
-      field_2_first_col = in.readUByte();
+    public TblPtg(RecordInputStream in) {
+      field_1_first_row = in.readUShort();
+      field_2_first_col = in.readUShort();
     }
-    
-    public void writeBytes(byte [] array, int offset)
-    {
-      array[offset+0]= (byte) (sid);
-      LittleEndian.putShort(array,offset+1,field_1_first_row);
-      LittleEndian.putByte(array,offset+3,field_2_first_col);
+
+    public void writeBytes(byte [] array, int offset) {
+      LittleEndian.putByte(array, offset+0, sid);
+      LittleEndian.putUShort(array, offset+1, field_1_first_row);
+      LittleEndian.putUShort(array, offset+3, field_2_first_col);
     }
 
-    public int getSize()
-    {
+    public int getSize() {
         return SIZE;
     }
-    
-    public short getRow() {
+
+    public int getRow() {
       return field_1_first_row;
     }
 
-    public short getColumn() {
+    public int getColumn() {
       return field_2_first_col;
-    }    
+    }
 
     public String toFormulaString(Workbook book)
     {
-    	// table(....)[][]
+        // table(....)[][]
         throw new RecordFormatException("Table and Arrays are not yet supported");
     }
-    
-    public String toString()
-    {
+
+    public String toString() {
         StringBuffer buffer = new StringBuffer("[Data Table - Parent cell is an interior cell in a data table]\n");
         buffer.append("top left row = ").append(getRow()).append("\n");
         buffer.append("top left col = ").append(getColumn()).append("\n");
         return buffer.toString();
-    }    
+    }
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java?rev=689811&r1=689810&r2=689811&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java Thu Aug 28 06:26:12 2008
@@ -189,40 +189,25 @@
     /**
      * used internally -- given a cell value record, figure out its type
      */
-    private int determineType(CellValueRecordInterface cval)
-    {
+    private static int determineType(CellValueRecordInterface cval) {
+    	if (cval instanceof FormulaRecordAggregate) {
+    		return HSSFCell.CELL_TYPE_FORMULA;
+    	}
+    	// all others are plain BIFF records
         Record record = ( Record ) cval;
-        int    sid    = record.getSid();
-        int    retval = 0;
-
-        switch (sid)
-        {
-
-            case NumberRecord.sid :
-                retval = HSSFCell.CELL_TYPE_NUMERIC;
-                break;
-
-            case BlankRecord.sid :
-                retval = HSSFCell.CELL_TYPE_BLANK;
-                break;
-
-            case LabelSSTRecord.sid :
-                retval = HSSFCell.CELL_TYPE_STRING;
-                break;
-
-            case FormulaRecordAggregate.sid :
-                retval = HSSFCell.CELL_TYPE_FORMULA;
-                break;
+        switch (record.getSid()) {
 
+            case NumberRecord.sid :   return HSSFCell.CELL_TYPE_NUMERIC;
+            case BlankRecord.sid :    return HSSFCell.CELL_TYPE_BLANK;
+            case LabelSSTRecord.sid : return HSSFCell.CELL_TYPE_STRING;
             case BoolErrRecord.sid :
                 BoolErrRecord boolErrRecord = ( BoolErrRecord ) record;
 
-                retval = (boolErrRecord.isBoolean())
+                return boolErrRecord.isBoolean()
                          ? HSSFCell.CELL_TYPE_BOOLEAN
                          : HSSFCell.CELL_TYPE_ERROR;
-                break;
         }
-        return retval;
+        throw new RuntimeException("Bad cell value rec (" + cval.getClass().getName() + ")");
     }
     
     /**

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=689811&r1=689810&r2=689811&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 28 06:26:12 2008
@@ -24,6 +24,7 @@
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.eventmodel.ERFListener;
 import org.apache.poi.hssf.eventmodel.EventRecordFactory;
 import org.apache.poi.hssf.record.BOFRecord;
@@ -32,6 +33,7 @@
 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.FormulaRecord;
 import org.apache.poi.hssf.record.GutsRecord;
 import org.apache.poi.hssf.record.IndexRecord;
 import org.apache.poi.hssf.record.MergeCellsRecord;
@@ -39,9 +41,13 @@
 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.WindowTwoRecord;
 import org.apache.poi.hssf.record.aggregates.ColumnInfoRecordsAggregate;
+import org.apache.poi.hssf.record.aggregates.MergedCellsTable;
 import org.apache.poi.hssf.record.aggregates.PageSettingsBlock;
 import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.util.CellRangeAddress;
@@ -57,6 +63,7 @@
         List records = new ArrayList();
         records.add( new BOFRecord() );
         records.add( new DimensionsRecord() );
+        records.add(createWindow2Record());
         records.add(EOFRecord.instance);
         Sheet sheet = Sheet.createSheet( records, 0, 0 );
 
@@ -65,9 +72,22 @@
         assertTrue( sheet.records.get(pos++) instanceof ColumnInfoRecordsAggregate );
         assertTrue( sheet.records.get(pos++) instanceof DimensionsRecord );
         assertTrue( sheet.records.get(pos++) instanceof RowRecordsAggregate );
+        assertTrue( sheet.records.get(pos++) instanceof WindowTwoRecord );
+        assertTrue( sheet.records.get(pos++) instanceof MergedCellsTable );
         assertTrue( sheet.records.get(pos++) instanceof EOFRecord );
     }
 
+    private static Record createWindow2Record() {
+        WindowTwoRecord result = new WindowTwoRecord();
+        result.setOptions(( short ) 0x6b6);
+        result.setTopRow(( short ) 0);
+        result.setLeftCol(( short ) 0);
+        result.setHeaderColor(0x40);
+        result.setPageBreakZoom(( short ) 0);
+        result.setNormalZoom(( short ) 0);
+        return result;
+    }
+
     private static final class MergedCellListener implements ERFListener {
 
         private int _count;
@@ -168,6 +188,8 @@
         records.add(new RowRecord(0));
         records.add(new RowRecord(1));
         records.add(new RowRecord(2));
+        records.add(createWindow2Record());
+        records.add(EOFRecord.instance);
         records.add(merged);
 
         Sheet sheet = Sheet.createSheet(records, 0);
@@ -193,11 +215,15 @@
     public void testRowAggregation() {
         List records = new ArrayList();
 
+        records.add(Sheet.createBOF());
         records.add(new DimensionsRecord());
         records.add(new RowRecord(0));
         records.add(new RowRecord(1));
+        records.add(new FormulaRecord());
         records.add(new StringRecord());
         records.add(new RowRecord(2));
+        records.add(createWindow2Record());
+        records.add(EOFRecord.instance);
 
         Sheet sheet = Sheet.createSheet(records, 0);
         assertNotNull("Row [2] was skipped", sheet.getRow(2));
@@ -400,6 +426,7 @@
         records.add(new BOFRecord());
         records.add(new UncalcedRecord());
         records.add(new DimensionsRecord());
+        records.add(createWindow2Record());
         records.add(EOFRecord.instance);
         Sheet sheet = Sheet.createSheet(records, 0, 0);
 
@@ -408,7 +435,7 @@
         if (serializedSize != estimatedSize) {
             throw new AssertionFailedError("Identified bug 45066 b");
         }
-        assertEquals(68, serializedSize);
+        assertEquals(90, serializedSize);
     }
 
     /**
@@ -502,5 +529,17 @@
         }
         assertEquals(1, count);
     }
+    
+    public void testMisplacedMergedCellsRecords_bug45699() {
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex45698-22488.xls");
+        
+        HSSFSheet sheet = wb.getSheetAt(0);
+        HSSFRow row = sheet.getRow(3);
+        HSSFCell cell = row.getCell(4);
+        if (cell == null) {
+            throw new AssertionFailedError("Identified bug 45699");
+        }
+        assertEquals("Informations", cell.getRichStringCellValue().getString());
+    }
 }
 

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestFormulaRecordAggregate.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestFormulaRecordAggregate.java?rev=689811&r1=689810&r2=689811&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestFormulaRecordAggregate.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestFormulaRecordAggregate.java Thu Aug 28 06:26:12 2008
@@ -29,23 +29,13 @@
  *
  * @author  avik
  */
-public class TestFormulaRecordAggregate extends junit.framework.TestCase {
+public final class TestFormulaRecordAggregate extends junit.framework.TestCase {
     
-    /** Creates a new instance of TestFormulaRecordAggregate */
-    public TestFormulaRecordAggregate(String arg) {
-        super(arg);
-    }
-    
-    public void testClone() {
+    public void testBasic() throws Exception {
         FormulaRecord f = new FormulaRecord();
         StringRecord s = new StringRecord();
+        s.setString("abc");
         FormulaRecordAggregate fagg = new FormulaRecordAggregate(f,s);
-        FormulaRecordAggregate newFagg = (FormulaRecordAggregate) fagg.clone();
-        assertTrue("objects are different", fagg!=newFagg);
-        assertTrue("deep clone", fagg.getFormulaRecord() != newFagg.getFormulaRecord());
-        assertTrue("deep clone",  fagg.getStringRecord() != newFagg.getStringRecord());
-
-        
+        assertEquals("abc", fagg.getStringValue());
     }
-    
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java?rev=689811&r1=689810&r2=689811&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java Thu Aug 28 06:26:12 2008
@@ -17,8 +17,6 @@
 
 package org.apache.poi.hssf.record.aggregates;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -32,31 +30,27 @@
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.record.BlankRecord;
 import org.apache.poi.hssf.record.FormulaRecord;
-import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RecordBase;
 import org.apache.poi.hssf.record.SharedFormulaRecord;
-import org.apache.poi.hssf.record.UnknownRecord;
-import org.apache.poi.hssf.record.WindowOneRecord;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
-public class TestValueRecordsAggregate extends TestCase
-{
+public final class TestValueRecordsAggregate extends TestCase {
     private static final String ABNORMAL_SHARED_FORMULA_FLAG_TEST_FILE = "AbnormalSharedFormulaFlag.xls";
-    ValueRecordsAggregate valueRecord = new ValueRecordsAggregate();
+    private final ValueRecordsAggregate valueRecord = new ValueRecordsAggregate();
 
     /**
      * Make sure the shared formula DOESNT makes it to the FormulaRecordAggregate when being parsed
      * as part of the value records
      */
-    public void testSharedFormula()
-    {
+    public void testSharedFormula() {
         List records = new ArrayList();
         records.add( new FormulaRecord() );
         records.add( new SharedFormulaRecord() );
 
-        valueRecord.construct( 0, records );
+        constructValueRecord(records);
         Iterator iterator = valueRecord.getIterator();
-        Record record = (Record) iterator.next();
+        RecordBase record = (RecordBase) iterator.next();
         assertNotNull( "Row contains a value", record );
         assertTrue( "First record is a FormulaRecordsAggregate", ( record instanceof FormulaRecordAggregate ) );
         //Ensure that the SharedFormulaRecord has been converted
@@ -64,39 +58,25 @@
 
     }
 
-    public void testUnknownRecordsIgnored()
-    {
-        List records = testData();
-        valueRecord.construct( 0, records );
-        Iterator iterator = valueRecord.getIterator();
-        Record record1 = (Record) iterator.next();
-        Record record2 = (Record) iterator.next();
-        assertNotNull( "No record found", record1 );
-        assertNotNull( "No record found", record2 );
-        assertFalse( iterator.hasNext() );
-
+    private void constructValueRecord(List records) {
+        SharedFormulaHolder sfrh = SharedFormulaHolder.create(records, 0, records.size());
+        valueRecord.construct(records, 0, records.size(), sfrh );
     }
 
-    private List testData(){
+    private static List testData() {
         List records = new ArrayList();
         FormulaRecord formulaRecord = new FormulaRecord();
-        UnknownRecord unknownRecord = new UnknownRecord();
         BlankRecord blankRecord = new BlankRecord();
-        WindowOneRecord windowOneRecord = new WindowOneRecord();
         formulaRecord.setRow( 1 );
         formulaRecord.setColumn( (short) 1 );
         blankRecord.setRow( 2 );
         blankRecord.setColumn( (short) 2 );
         records.add( formulaRecord );
-        records.add( unknownRecord );
         records.add( blankRecord );
-        records.add( windowOneRecord );
         return records;
     }
 
-    public void testInsertCell()
-            throws Exception
-    {
+    public void testInsertCell() {
         Iterator iterator = valueRecord.getIterator();
         assertFalse( iterator.hasNext() );
 
@@ -118,8 +98,7 @@
         valueRecord.removeCell( blankRecord2 );
     }
 
-    public void testGetPhysicalNumberOfCells() throws Exception
-    {
+    public void testGetPhysicalNumberOfCells() {
         assertEquals(0, valueRecord.getPhysicalNumberOfCells());
         BlankRecord blankRecord1 = newBlankRecord();
         valueRecord.insertCell( blankRecord1 );
@@ -128,8 +107,7 @@
         assertEquals(0, valueRecord.getPhysicalNumberOfCells());
     }
 
-    public void testGetFirstCellNum() throws Exception
-    {
+    public void testGetFirstCellNum() {
         assertEquals( -1, valueRecord.getFirstCellNum() );
         valueRecord.insertCell( newBlankRecord( 2, 2 ) );
         assertEquals( 2, valueRecord.getFirstCellNum() );
@@ -141,8 +119,7 @@
         assertEquals( 2, valueRecord.getFirstCellNum() );
     }
 
-    public void testGetLastCellNum() throws Exception
-    {
+    public void testGetLastCellNum() {
         assertEquals( -1, valueRecord.getLastCellNum() );
         valueRecord.insertCell( newBlankRecord( 2, 2 ) );
         assertEquals( 2, valueRecord.getLastCellNum() );
@@ -155,8 +132,7 @@
 
     }
 
-    public void testSerialize() throws Exception
-    {
+    public void testSerialize() {
         byte[] actualArray = new byte[36];
         byte[] expectedArray = new byte[]
         {
@@ -171,7 +147,7 @@
             (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00,
         };
         List records = testData();
-        valueRecord.construct( 0, records );
+        constructValueRecord(records);
         int bytesWritten = valueRecord.serializeCellRow(1, 0, actualArray );
         bytesWritten += valueRecord.serializeCellRow(2, bytesWritten, actualArray );
         assertEquals( 36, bytesWritten );
@@ -179,18 +155,12 @@
             assertEquals( expectedArray[i], actualArray[i] );
     }
 
-    public static void main( String[] args )
-    {
-        System.out.println( "Testing org.apache.poi.hssf.record.aggregates.TestValueRecordAggregate" );
-        junit.textui.TestRunner.run( TestValueRecordsAggregate.class );
-    }
-
-    private BlankRecord newBlankRecord()
+    private static BlankRecord newBlankRecord()
     {
         return newBlankRecord( 2, 2 );
     }
 
-    private BlankRecord newBlankRecord( int col, int row)
+    private static BlankRecord newBlankRecord( int col, int row)
     {
         BlankRecord blankRecord = new BlankRecord();
         blankRecord.setRow( row );
@@ -300,5 +270,4 @@
         
         return crc.getValue();
     }
-
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestLinkTable.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestLinkTable.java?rev=689811&r1=689810&r2=689811&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestLinkTable.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestLinkTable.java Thu Aug 28 06:26:12 2008
@@ -41,4 +41,19 @@
 		
 		assertEquals("ipcSummenproduktIntern($C5,N$2,$A$9,N$1)", formula);
 	}
+	
+	public void testMultipleExternSheetRecords_bug45698() {
+		HSSFWorkbook wb;
+
+		try {
+			wb = HSSFTestDataSamples.openSampleWorkbook("ex45698-22488.xls");
+		} catch (RuntimeException e) {
+			if ("Extern sheet is part of LinkTable".equals(e.getMessage())) {
+				throw new AssertionFailedError("Identified bug 45698");
+			}
+			throw e;
+		}
+		// some other sanity checks
+		assertEquals(7, wb.getNumberOfSheets());
+	}
 }



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