poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r759112 [1/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
Author: yegor
Date: Fri Mar 27 11:50:52 2009
New Revision: 759112

URL: http://svn.apache.org/viewvc?rev=759112&view=rev
Log:
improved test cases: moved common hssf-xssf test to org.apache.poi.ss namespace, removed duplicate tests, refactored code to throw same exceptions, etc

Added:
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java   (with props)
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java   (with props)
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java   (with props)
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java   (with props)
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java   (with props)
Removed:
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetOrder.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheetSetOrder.java
Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFName.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
    poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/FormulaError.java
    poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
    poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPicture.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDialogSheet.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java Fri Mar 27 11:50:52 2009
@@ -285,7 +285,7 @@
 		retval.setVResolution(( short ) 300);
 		retval.setHeaderMargin( 0.5);
 		retval.setFooterMargin( 0.5);
-		retval.setCopies(( short ) 0);
+		retval.setCopies(( short ) 1);
 		return retval;
 	}
 
@@ -352,7 +352,7 @@
 			case Sheet.TopMargin:    return _topMargin;
 			case Sheet.BottomMargin: return _bottomMargin;
 		}
-		throw new RuntimeException( "Unknown margin constant:  " + marginIndex );
+		throw new IllegalArgumentException( "Unknown margin constant:  " + marginIndex );
 	}
 
 
@@ -372,7 +372,7 @@
 			case Sheet.TopMargin:    return 1.0;
 			case Sheet.BottomMargin: return 1.0;
 		}
-		throw new RuntimeException( "Unknown margin constant:  " + margin );
+		throw new IllegalArgumentException( "Unknown margin constant:  " + margin );
 	}
 
 	/**
@@ -401,7 +401,7 @@
 					m = _bottomMargin;
 					break;
 				default :
-					throw new RuntimeException( "Unknown margin constant:  " + margin );
+					throw new IllegalArgumentException( "Unknown margin constant:  " + margin );
 			}
 		}
 		m.setMargin( size );

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java Fri Mar 27 11:50:52 2009
@@ -91,7 +91,7 @@
     /**
      * The maximum  number of columns in BIFF8
      */
-    private static final int LAST_COLUMN_NUMBER  = 255; // 2^8 - 1
+    public static final int LAST_COLUMN_NUMBER  = 255; // 2^8 - 1
     private static final String LAST_COLUMN_NAME  = "IV";
     
     public final static short        ENCODING_UNCHANGED          = -1;
@@ -626,6 +626,9 @@
     }
 
     public String getCellFormula() {
+        if (!(_record instanceof FormulaRecordAggregate)) {
+            throw typeMismatch(CELL_TYPE_FORMULA, _cellType, true);
+        }
         return HSSFFormulaParser.toFormulaString(_book, ((FormulaRecordAggregate)_record).getFormulaTokens());
     }
 

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFName.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFName.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFName.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFName.java Fri Mar 27 11:50:52 2009
@@ -124,6 +124,7 @@
             if (rec != _definedNameRec) {
                 if (rec.getNameText().equalsIgnoreCase(nameName) && sheetNumber == rec.getSheetNumber()){
                     String msg = "The "+(sheetNumber == 0 ? "workbook" : "sheet")+" already contains this name: " + nameName;
+                    _definedNameRec.setNameText(nameName + "(2)");
                     throw new IllegalArgumentException(msg);
                 }
             }

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java Fri Mar 27 11:50:52 2009
@@ -437,15 +437,17 @@
     /**
      * set the row's height or set to ff (-1) for undefined/default-height.  Set the height in "twips" or
      * 1/20th of a point.
-     * @param height  rowheight or 0xff for undefined (use sheet default)
+     * @param height  rowheight or -1 for undefined (use sheet default)
      */
 
     public void setHeight(short height)
     {
-
-        // row.setOptionFlags(
-        row.setBadFontHeight(true);
-        row.setHeight(height);
+        if(height == -1){
+            row.setHeight((short)(0xFF | 0x8000));
+        } else {
+            row.setBadFontHeight(true);
+            row.setHeight(height);
+        }
     }
 
     /**
@@ -466,15 +468,17 @@
 
     /**
      * set the row's height in points.
-     * @param height  row height in points
+     * @param height  row height in points, <code>-1</code> means to use the default height
      */
 
     public void setHeightInPoints(float height)
     {
-
-        // row.setOptionFlags(
-        row.setBadFontHeight(true);
-        row.setHeight((short) (height * 20));
+        if(height == -1){
+            row.setHeight((short)(0xFF | 0x8000));
+        } else {
+            row.setBadFontHeight(true);
+            row.setHeight((short) (height * 20));
+        }
     }
 
     /**

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Fri Mar 27 11:50:52 2009
@@ -67,18 +67,6 @@
     private static final POILogger log = POILogFactory.getLogger(HSSFSheet.class);
     private static final int DEBUG = POILogger.DEBUG;
 
-    /* Constants for margins */
-    public static final short LeftMargin = Sheet.LeftMargin;
-    public static final short RightMargin = Sheet.RightMargin;
-    public static final short TopMargin = Sheet.TopMargin;
-    public static final short BottomMargin = Sheet.BottomMargin;
-
-    public static final byte PANE_LOWER_RIGHT = (byte)0;
-    public static final byte PANE_UPPER_RIGHT = (byte)1;
-    public static final byte PANE_LOWER_LEFT = (byte)2;
-    public static final byte PANE_UPPER_LEFT = (byte)3;
-
-
     /**
      * Used for compile-time optimization.  This is the initial size for the collection of
      * rows.  It is currently set to 20.  If you generate larger sheets you may benefit
@@ -236,14 +224,16 @@
      */
     public void removeRow(Row row) {
         HSSFRow hrow = (HSSFRow) row;
+        if (row.getSheet() != this) {
+            throw new IllegalArgumentException("Specified row does not belong to this sheet");
+        }
+
         if (_rows.size() > 0) {
             Integer key = new Integer(row.getRowNum());
             HSSFRow removedRow = _rows.remove(key);
             if (removedRow != row) {
-                if (removedRow != null) {
-                    _rows.put(key, removedRow);
-                }
-                throw new RuntimeException("Specified row does not belong to this sheet");
+                //should not happen if the input argument is valid
+                throw new IllegalArgumentException("Specified row does not belong to this sheet");
             }
             if (hrow.getRowNum() == getLastRowNum())
             {
@@ -488,7 +478,7 @@
 
     public float getDefaultRowHeightInPoints()
     {
-        return (_sheet.getDefaultRowHeight() / 20);
+        return ((float)_sheet.getDefaultRowHeight() / 20);
     }
 
     /**
@@ -1434,9 +1424,9 @@
      * Sets a page break at the indicated column
      * @param column
      */
-    public void setColumnBreak(short column) {
-        validateColumn(column);
-        _sheet.getPageSettings().setColumnBreak(column, (short)0, (short)65535);
+    public void setColumnBreak(int column) {
+        validateColumn((short)column);
+        _sheet.getPageSettings().setColumnBreak((short)column, (short)0, (short)65535);
     }
 
     /**
@@ -1444,7 +1434,7 @@
      * @param column FIXME: Document this!
      * @return FIXME: Document this!
      */
-    public boolean isColumnBroken(short column) {
+    public boolean isColumnBroken(int column) {
         return _sheet.getPageSettings().isColumnBroken(column);
     }
 
@@ -1452,7 +1442,7 @@
      * Removes a page break at the indicated column
      * @param column
      */
-    public void removeColumnBreak(short column) {
+    public void removeColumnBreak(int column) {
         _sheet.getPageSettings().removeColumnBreak(column);
     }
 
@@ -1857,4 +1847,16 @@
     public HSSFSheetConditionalFormatting getSheetConditionalFormatting() {
         return new HSSFSheetConditionalFormatting(this);
     }
+
+    /**
+     * Returns the name of this sheet
+     *
+     * @return the name of this sheet
+     */
+    public String getSheetName() {
+        HSSFWorkbook wb = getWorkbook();
+        int idx = wb.getSheetIndex(this);
+        return wb.getSheetName(idx);
+    }
+
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Fri Mar 27 11:50:52 2009
@@ -752,8 +752,8 @@
 
         HSSFSheet sheet = new HSSFSheet(this);
 
+        workbook.setSheetName(_sheets.size(), sheetname);
         _sheets.add(sheet);
-        workbook.setSheetName(_sheets.size() - 1, sheetname);
         boolean isOnlySheet = _sheets.size() == 1;
         sheet.setSelected(isOnlySheet);
         sheet.setActive(isOnlySheet);
@@ -788,6 +788,7 @@
 
     public HSSFSheet getSheetAt(int index)
     {
+        validateSheetIndex(index);
         return (HSSFSheet) _sheets.get(index);
     }
 

Modified: poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/FormulaError.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/FormulaError.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/FormulaError.java (original)
+++ poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/FormulaError.java Fri Mar 27 11:50:52 2009
@@ -106,7 +106,7 @@
     /**
      * @return numeric code of the error
      */
-    public int getCode() {
+    public byte getCode() {
         return type;
     }
 
@@ -118,7 +118,7 @@
     }
 
     private static Map<String, FormulaError> smap = new HashMap<String, FormulaError>();
-    private static Map<Integer, FormulaError> imap = new HashMap<Integer, FormulaError>();
+    private static Map<Byte, FormulaError> imap = new HashMap<Byte, FormulaError>();
     static{
         for (FormulaError error : values()) {
             imap.put(error.getCode(), error);
@@ -126,7 +126,7 @@
         }
     }
 
-    public static FormulaError forInt(int type){
+    public static FormulaError forInt(byte type){
         FormulaError err = imap.get(type);
         if(err == null) throw new IllegalArgumentException("Unknown error type: " + type);
         return err;

Modified: poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java (original)
+++ poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java Fri Mar 27 11:50:52 2009
@@ -225,6 +225,11 @@
     boolean getHorizontallyCenter();
 
     /**
+     * Determine whether printed output for this sheet will be vertically centered.
+     */
+    boolean getVerticallyCenter();
+
+    /**
      * Removes a merged region of cells (hence letting them free)
      *
      * @param index of the region to unmerge
@@ -639,20 +644,20 @@
      * Sets a page break at the indicated column
      * @param column
      */
-    void setColumnBreak(short column);
+    void setColumnBreak(int column);
 
     /**
      * Determines if there is a page break at the indicated column
      * @param column FIXME: Document this!
      * @return FIXME: Document this!
      */
-    boolean isColumnBroken(short column);
+    boolean isColumnBroken(int column);
 
     /**
      * Removes a page break at the indicated column
      * @param column
      */
-    void removeColumnBreak(short column);
+    void removeColumnBreak(int column);
 
     /**
      * Expands or collapses a column group.
@@ -761,4 +766,18 @@
      * @return the parent workbook
      */
     Workbook getWorkbook();
+
+    /**
+     * Returns the name of this sheet
+     *
+     * @return the name of this sheet
+     */
+    String getSheetName();
+
+    /**
+     * Note - this is not the same as whether the sheet is focused (isActive)
+     * @return <code>true</code> if this sheet is currently selected
+     */
+    boolean isSelected();
+
 }

Modified: poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java (original)
+++ poi/trunk/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java Fri Mar 27 11:50:52 2009
@@ -97,7 +97,7 @@
      * @see Sheet#setSelected(boolean)
      * @param index the index of the sheet to select (0 based)
      */
-    void setSelectedTab(short index);
+    void setSelectedTab(int index);
 
     /**
      * Set the sheet name.

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java Fri Mar 27 11:50:52 2009
@@ -60,8 +60,7 @@
     /**
      * The maximum  number of columns in SpreadsheetML
      */
-    public static final int MAX_COLUMN_NUMBER  = 16384; // 2^14
-    private static final int LAST_COLUMN_NUMBER  = MAX_COLUMN_NUMBER-1;
+    public static final int LAST_COLUMN_NUMBER  = 16384-1; //2^14-1
     private static final String LAST_COLUMN_NAME  = "XFD";
 
     private static final String FALSE_AS_STRING = "0";
@@ -194,7 +193,6 @@
         switch(cellType) {
             case CELL_TYPE_BLANK:
                 return 0.0;
-            case CELL_TYPE_ERROR:
             case CELL_TYPE_FORMULA:
             case CELL_TYPE_NUMERIC:
                 return cell.isSetV() ? Double.parseDouble(cell.getV()) : 0.0;
@@ -708,7 +706,7 @@
                     CTCellFormula f =  CTCellFormula.Factory.newInstance();
                     f.setStringValue("0");
                     cell.setF(f);
-                    cell.unsetT();
+                    if(cell.isSetT()) cell.unsetT();
                 }
                 break;
             default:

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPicture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPicture.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPicture.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPicture.java Fri Mar 27 11:50:52 2009
@@ -18,6 +18,7 @@
 
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.*;
 import org.openxmlformats.schemas.drawingml.x2006.main.*;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.usermodel.Picture;
 import org.apache.poi.util.POILogger;
@@ -44,6 +45,15 @@
     private static final POILogger logger = POILogFactory.getLogger(XSSFPicture.class);
 
     /**
+     * Column width measured as the number of characters of the maximum digit width of the
+     * numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. There are 4 pixels of margin
+     * padding (two on each side), plus 1 pixel padding for the gridlines.
+     *
+     * This value is the same for default font in Office 2007 (Calibry) and Office 2003 and earlier (Arial)
+     */
+    private static float DEFAULT_COLUMN_WIDTH = 9.140625f;
+
+    /**
      * A default instance of CTShape used for creating new shapes.
      */
     private static CTPicture prototype = null;
@@ -230,9 +240,11 @@
 
     private float getColumnWidthInPixels(int columnIndex){
         XSSFSheet sheet = (XSSFSheet)getDrawing().getParent();
-        float numChars = (float)sheet.getColumnWidth(columnIndex)/256;
 
-        return numChars*XSSFWorkbook.DEFAULT_CHARACTER_WIDTH;
+        CTCol col = sheet.getColumnHelper().getColumn(columnIndex, false);
+        double numChars = col == null || !col.isSetWidth() ? DEFAULT_COLUMN_WIDTH : col.getWidth();
+
+        return (float)numChars*XSSFWorkbook.DEFAULT_CHARACTER_WIDTH;
     }
 
     private float getRowHeightInPixels(int rowIndex){

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java Fri Mar 27 11:50:52 2009
@@ -45,7 +45,7 @@
     /**
      * The maximum  number of rows in SpreadsheetML
      */
-    public static final int MAX_ROW_NUMBER  = 1048576; //2 ^ 20
+    public static final int MAX_ROW_NUMBER  = 1048575; //2 ^ 20 - 1
 
     /**
      * the xml bean containing all cell definitions for this row
@@ -170,8 +170,6 @@
      * @see Cell#CELL_TYPE_STRING
      */
     public XSSFCell createCell(int columnIndex, int type) {
-        if(columnIndex < 0) throw new IllegalArgumentException("columnIndex must be >= 0, was " + columnIndex);
-
         CTCell ctcell = CTCell.Factory.newInstance();
         XSSFCell xcell = new XSSFCell(this, ctcell);
         xcell.setCellNum(columnIndex);
@@ -333,10 +331,9 @@
      * @throws IllegalArgumentException if rowNum < 0 or greater than {@link #MAX_ROW_NUMBER}
      */
     public void setRowNum(int rowIndex) {
-        if (rowIndex < 0 || rowIndex >= MAX_ROW_NUMBER) {
-            throw new IllegalArgumentException("Invalid row index (" + rowIndex 
-                    + ").  Allowable row range for " + FILE_FORMAT_NAME 
-                    + " is (0.." + (MAX_ROW_NUMBER-1) + ")");
+        if (rowIndex < 0 || rowIndex > MAX_ROW_NUMBER) {
+            throw new IllegalArgumentException("Invalid row number (" + rowIndex 
+                    + ") outside allowable range (0.." + MAX_ROW_NUMBER + ")");
         }
         row.setR(rowIndex + 1);
     }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Fri Mar 27 11:50:52 2009
@@ -64,15 +64,6 @@
 public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
     private static final POILogger logger = POILogFactory.getLogger(XSSFSheet.class);
 
-    /**
-     * Column width measured as the number of characters of the maximum digit width of the
-     * numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. There are 4 pixels of margin
-     * padding (two on each side), plus 1 pixel padding for the gridlines.
-     *
-     * This value is the same for default font in Office 2007 (Calibry) and Office 2003 and earlier (Arial)
-     */
-    private static float DEFAULT_COLUMN_WIDTH = 9.140625f;
-
     protected CTSheet sheet;
     protected CTWorksheet worksheet;
     private TreeMap<Integer, XSSFRow> rows;
@@ -462,7 +453,7 @@
      */
     public int getColumnWidth(int columnIndex) {
         CTCol col = columnHelper.getColumn(columnIndex, false);
-        double width = col == null || !col.isSetWidth() ? DEFAULT_COLUMN_WIDTH : col.getWidth();
+        double width = col == null || !col.isSetWidth() ? getDefaultColumnWidth() : col.getWidth();
         return (int)(width*256);
     }
 
@@ -512,8 +503,8 @@
      *  set for that column
      */
     public CellStyle getColumnStyle(int column) {
-    	// TODO
-    	return null;
+        int idx = columnHelper.getColDefaultStyle(column);
+        return getWorkbook().getCellStyleAt((short)(idx == -1 ? 0 : idx));
     }
 
 
@@ -568,7 +559,7 @@
      * @return the number of the first logical row on the sheet, zero based
      */
     public int getFirstRowNum() {
-        return rows.size() == 0 ? -1 : rows.firstKey();
+        return rows.size() == 0 ? 0 : rows.firstKey();
     }
 
     /**
@@ -681,7 +672,7 @@
     }
 
     public int getLastRowNum() {
-        return rows.size() == 0 ? -1 : rows.lastKey();
+        return rows.size() == 0 ? 0 : rows.lastKey();
     }
 
     public short getLeftCol() {
@@ -720,7 +711,7 @@
             case FooterMargin:
                 return pageMargins.getFooter();
             default :
-                throw new POIXMLException("Unknown margin constant:  " + margin);
+                throw new IllegalArgumentException("Unknown margin constant:  " + margin);
         }
     }
 
@@ -742,16 +733,24 @@
         switch (margin) {
             case LeftMargin:
                 pageMargins.setLeft(size);
+                break;
             case RightMargin:
                 pageMargins.setRight(size);
+                break;
             case TopMargin:
                 pageMargins.setTop(size);
+                break;
             case BottomMargin:
                 pageMargins.setBottom(size);
+                break;
             case HeaderMargin:
                 pageMargins.setHeader(size);
+                break;
             case FooterMargin:
                 pageMargins.setFooter(size);
+                break;
+            default :
+                throw new IllegalArgumentException( "Unknown margin constant:  " + margin );
         }
     }
 
@@ -1033,7 +1032,7 @@
     /**
      * Determines if there is a page break at the indicated column
      */
-    public boolean isColumnBroken(short column) {
+    public boolean isColumnBroken(int column) {
         int[] colBreaks = getColumnBreaks();
         for (int i = 0 ; i < colBreaks.length ; i++) {
             if (colBreaks[i] == column) {
@@ -1167,7 +1166,7 @@
     /**
      * Removes a page break at the indicated column
      */
-    public void removeColumnBreak(short column) {
+    public void removeColumnBreak(int column) {
         CTBreak[] brkArray = getSheetTypeColumnBreaks().getBrkArray();
         for (int i = 0 ; i < brkArray.length ; i++) {
             if (brkArray[i].getId() == column) {
@@ -1202,6 +1201,10 @@
      * @param row  the row to remove.
      */
     public void removeRow(Row row) {
+        if (row.getSheet() != this) {
+            throw new IllegalArgumentException("Specified row does not belong to this sheet");
+        }
+
         rows.remove(row.getRowNum());
     }
 
@@ -1263,7 +1266,7 @@
      *
      * @param column the column to break
      */
-    public void setColumnBreak(short column) {
+    public void setColumnBreak(int column) {
         if (! isColumnBroken(column)) {
             CTBreak brk = getSheetTypeColumnBreaks().addNewBrk();
             brk.setId(column);

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Fri Mar 27 11:50:52 2009
@@ -60,17 +60,7 @@
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlOptions;
 import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookView;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookViews;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedNames;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STSheetState;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
 
 /**
  * High level representation of a SpreadsheetML workbook.  This is the first object most users
@@ -445,7 +435,7 @@
      * @return XSSFSheet representing the new sheet.
      */
     public XSSFSheet createSheet() {
-        String sheetname = "Sheet" + (sheets.size() + 1);
+        String sheetname = "Sheet" + (sheets.size());
         return createSheet(sheetname);
     }
 
@@ -777,6 +767,8 @@
     public void removeSheetAt(int index) {
         validateSheetIndex(index);
 
+        XSSFSheet sheet = getSheetAt(index);
+        removeRelation(sheet);
         this.sheets.remove(index);
         this.workbook.getSheets().removeSheet(index);
     }
@@ -1009,7 +1001,7 @@
     /**
      * We only set one sheet as selected for compatibility with HSSF.
      */
-    public void setSelectedTab(short index) {
+    public void setSelectedTab(int index) {
         for (int i = 0 ; i < sheets.size() ; ++i) {
             XSSFSheet sheet = sheets.get(i);
             sheet.setSelected(i == index);
@@ -1042,10 +1034,16 @@
         int idx = getSheetIndex(sheetname);
         sheets.add(pos, sheets.remove(idx));
         // Reorder CTSheets
-        XmlObject cts = workbook.getSheets().getSheetArray(idx).copy();
+        CTSheets ct = workbook.getSheets();
+        XmlObject cts = ct.getSheetArray(idx).copy();
         workbook.getSheets().removeSheet(idx);
-        CTSheet newcts = workbook.getSheets().insertNewSheet(pos);
+        CTSheet newcts = ct.insertNewSheet(pos);
         newcts.set(cts);
+
+        //notify sheets
+        for(int i=0; i < sheets.size(); i++) {
+            sheets.get(i).sheet = ct.getSheetArray(i);
+        }
     }
 
     /**

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java Fri Mar 27 11:50:52 2009
@@ -31,27 +31,8 @@
         return XSSFITestDataProvider.getInstance();
     }
 
-    public void testSetValues() {
-        baseTestSetValues();
-    }
-
-   public void testBoolErr() {
-        baseTestBoolErr();
-    }
-
-    public void testFormulaStyle() {
-        baseTestFormulaStyle();
-    }
-
-    public void testToString() {
-        baseTestToString();
-    }
-
-    public void testSetFormulaValue() {
-        baseTestSetFormulaValue();
-    }
-
     public void testChangeCellType() {
+        //for performance reasons combine baseTestChangeType* together 
         Workbook wb = getTestDataProvider().createWorkbook();
         Row row = wb.createSheet().createRow(0);
         baseTestChangeTypeStringToBool(row.createCell(0));
@@ -62,6 +43,4 @@
         //TODO: works in HSSF but fails in XSSF
         //baseTestChangeTypeFormulaToBoolean(row.createCell(4));
     }
-
-
 }
\ No newline at end of file

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDialogSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDialogSheet.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDialogSheet.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDialogSheet.java Fri Mar 27 11:50:52 2009
@@ -66,48 +66,7 @@
         assertFalse(sheet.getFitToPage());
     }
     
-    public void testGetSetMargin() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
-        assertEquals((double) 0, sheet.getMargin((short) 0));
-        sheet.setMargin((short) 0, 10);
-        assertEquals((double) 10, sheet.getMargin((short) 0));
-        assertEquals((double) 10, sheet.getMargin((short) 1));
-        assertEquals((double) 10, sheet.getMargin((short) 2));
-        assertEquals((double) 10, sheet.getMargin((short) 3));
-        assertEquals((double) 10, sheet.getMargin((short) 4));
-        assertEquals((double) 10, sheet.getMargin((short) 5));
-        sheet.setMargin((short) 1, 11);
-        assertEquals((double) 11, sheet.getMargin((short) 1));
-        assertEquals((double) 11, sheet.getMargin((short) 2));
-        assertEquals((double) 11, sheet.getMargin((short) 3));
-        assertEquals((double) 11, sheet.getMargin((short) 4));
-        assertEquals((double) 11, sheet.getMargin((short) 5));
-        sheet.setMargin((short) 2, 12);
-        assertEquals((double) 12, sheet.getMargin((short) 2));
-        assertEquals((double) 12, sheet.getMargin((short) 3));
-        assertEquals((double) 12, sheet.getMargin((short) 4));
-        assertEquals((double) 12, sheet.getMargin((short) 5));
-        sheet.setMargin((short) 3, 13);
-        assertEquals((double) 13, sheet.getMargin((short) 3));
-        assertEquals((double) 13, sheet.getMargin((short) 4));
-        assertEquals((double) 13, sheet.getMargin((short) 5));
-        sheet.setMargin((short) 4, 14);
-        assertEquals((double) 14, sheet.getMargin((short) 4));
-        assertEquals((double) 14, sheet.getMargin((short) 5));
-        sheet.setMargin((short) 5, 15);
-        assertEquals((double) 15, sheet.getMargin((short) 5));
-        
-        // Test that nothing happens if another margin constant is given (E.G. 65)
-        sheet.setMargin((short) 65, 15);
-        assertEquals((double) 10, sheet.getMargin((short) 0));
-        assertEquals((double) 11, sheet.getMargin((short) 1));
-        assertEquals((double) 12, sheet.getMargin((short) 2));
-        assertEquals((double) 13, sheet.getMargin((short) 3));
-        assertEquals((double) 14, sheet.getMargin((short) 4));
-        assertEquals((double) 15, sheet.getMargin((short) 5));
-    }
-    
+   
     public void testGetFooter() {
         XSSFWorkbook workbook = new XSSFWorkbook();
         XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java Fri Mar 27 11:50:52 2009
@@ -18,144 +18,17 @@
 
 import junit.framework.TestCase;
 import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.apache.poi.ss.usermodel.BaseTestNamedRange;
 
 /**
  * @author Yegor Kozlov
  */
-public class TestXSSFName extends TestCase {
+public class TestXSSFName extends BaseTestNamedRange {
 
-    public void testCreate(){
-        // Create a new workbook
-        XSSFWorkbook wb = new XSSFWorkbook();
-
-        XSSFName name1 = wb.createName();
-        name1.setNameName("testOne");
-
-        //setting a duplicate name should throw IllegalArgumentException
-        XSSFName name2 = wb.createName();
-        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(1);
-            fail("should throw IllegalArgumentException");
-        } catch(IllegalArgumentException e){
-            assertEquals("Sheet index (1) is out of range", e.getMessage());
-        }
-        wb.createSheet();
-        try {
-            name1.setSheetIndex(1);
-            fail("should throw IllegalArgumentException");
-        } catch(IllegalArgumentException e){
-            assertEquals("Sheet index (1) is out of range (0..0)", e.getMessage());
-        }
-        wb.createSheet();
-        name1.setSheetIndex(1);
-        assertEquals(1, name1.getSheetIndex());
-    }
-
-    public void testUnicodeNamedRange() {
-        XSSFWorkbook workBook = new XSSFWorkbook();
-        workBook.createSheet("Test");
-        XSSFName name = workBook.createName();
-        name.setNameName("\u03B1");
-        name.setRefersToFormula("Test!$D$3:$E$8");
-
-
-        XSSFWorkbook workBook2 = XSSFTestDataSamples.writeOutAndReadBack(workBook);
-        XSSFName name2 = workBook2.getNameAt(0);
-
-        assertEquals("\u03B1", name2.getNameName());
-        assertEquals("Test!$D$3:$E$8", name2.getRefersToFormula());
-    }
-
-    public void testAddRemove() {
-        XSSFWorkbook wb = new XSSFWorkbook();
-        assertEquals(0, wb.getNumberOfNames());
-        XSSFName name1 = wb.createName();
-        name1.setNameName("name1");
-        assertEquals(1, wb.getNumberOfNames());
-
-        XSSFName name2 = wb.createName();
-        name2.setNameName("name2");
-        assertEquals(2, wb.getNumberOfNames());
-
-        XSSFName 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() {
-        XSSFWorkbook wb = new XSSFWorkbook();
-        wb.createSheet();
-        wb.createSheet();
-        
-        XSSFName 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);
+    @Override
+    protected XSSFITestDataProvider getTestDataProvider(){
+        return XSSFITestDataProvider.getInstance();
     }
 
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java Fri Mar 27 11:50:52 2009
@@ -23,12 +23,10 @@
 
 import junit.framework.TestCase;
 
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.model.SharedStringsTable;
 import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -37,303 +35,18 @@
 /**
  * Tests for XSSFRow
  */
-public final class TestXSSFRow extends TestCase {
+public final class TestXSSFRow extends BaseTestRow {
 
-    /**
-     * Test adding cells to a row in various places and see if we can find them again.
-     */
-    public void testAddAndIterateCells() {
-        XSSFSheet sheet = createParentObjects();
-        XSSFRow row = sheet.createRow(0);
-
-        // One cell at the beginning
-        Cell cell1 = row.createCell((short) 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((short) 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((short) 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((short) 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((short) 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());
-    }
-
-    public void testGetCell() {
-        XSSFRow row = getSampleRow();
-
-        assertNotNull(row.getCell((short) 2));
-        assertNotNull(row.getCell((short) 3));
-        assertNotNull(row.getCell((short) 4));
-        // cell3 may have been created as CELL_TYPE_NUMERIC, but since there is no numeric
-        // value set yet, its cell type is classified as 'blank'
-        assertEquals(Cell.CELL_TYPE_BLANK, row.getCell((short) 3).getCellType());
-        assertNull(row.getCell((short) 5));
-    }
-
-    public void testGetPhysicalNumberOfCells() {
-        XSSFRow row = getSampleRow();
-        assertEquals(7, row.getPhysicalNumberOfCells());
-    }
-
-    public void testGetFirstCellNum() {
-        // Test a row with some cells
-        XSSFRow row = getSampleRow();
-        assertFalse(row.getFirstCellNum() == (short) 0);
-        assertEquals((short) 2, row.getFirstCellNum());
-
-        // Test after removing the first cell
-        Cell cell = row.getCell((short) 2);
-        row.removeCell(cell);
-        assertFalse(row.getFirstCellNum() == (short) 2);
-
-        // Test a row without cells
-        XSSFSheet sheet = createParentObjects();
-        XSSFRow emptyRow = sheet.createRow(0);
-        assertEquals(-1, emptyRow.getFirstCellNum());
-    }
-
-    public void testGetSetHeight() {
-        XSSFRow row = getSampleRow();
-        // I assume that "ht" attribute value is in 'points', please verify that
-        // Test that no rowHeight is set
-        assertEquals(row.getSheet().getDefaultRowHeight(), row.getHeight());
-        // Set a rowHeight and test the new value
-        row.setHeight((short) 240);
-        assertEquals((short) 240.0, row.getHeight());
-        assertEquals(12.0f, row.getHeightInPoints());
-        // Set a new rowHeight in points and test the new value
-        row.setHeightInPoints(13);
-        assertEquals((float) 13.0, row.getHeightInPoints());
-        assertEquals((short)(13.0*20), row.getHeight());
-    }
-
-    public void testGetSetZeroHeight() throws Exception {
-        XSSFRow row = getSampleRow();
-        assertFalse(row.getZeroHeight());
-        row.setZeroHeight(true);
-        assertTrue(row.getZeroHeight());
-    }
-
-    /**
-     * Tests for the missing/blank cell policy stuff
-     */
-    public void testGetCellPolicy() throws Exception {
-        XSSFSheet sheet = createParentObjects();
-        XSSFRow row = sheet.createRow(0);
-
-        // 0 -> string
-        // 1 -> num
-        // 2 missing
-        // 3 missing
-        // 4 -> blank
-        // 5 -> num
-        row.createCell((short)0).setCellValue(new XSSFRichTextString("test"));
-        row.createCell((short)1).setCellValue(3.2);
-        row.createCell((short)4, Cell.CELL_TYPE_BLANK);
-        row.createCell((short)5).setCellValue(4);
-
-        // First up, no policy
-        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, XSSFRow.RETURN_BLANK_AS_NULL).getCellType());
-        assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(1, XSSFRow.RETURN_BLANK_AS_NULL).getCellType());
-        assertEquals(null, row.getCell(2, XSSFRow.RETURN_BLANK_AS_NULL));
-        assertEquals(null, row.getCell(3, XSSFRow.RETURN_BLANK_AS_NULL));
-        assertEquals(null, row.getCell(4, XSSFRow.RETURN_BLANK_AS_NULL));
-        assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(5, XSSFRow.RETURN_BLANK_AS_NULL).getCellType());
-
-        // CREATE_NULL_AS_BLANK - creates as needed
-        assertEquals(Cell.CELL_TYPE_STRING,  row.getCell(0, XSSFRow.CREATE_NULL_AS_BLANK).getCellType());
-        assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(1, XSSFRow.CREATE_NULL_AS_BLANK).getCellType());
-        assertEquals(Cell.CELL_TYPE_BLANK,   row.getCell(2, XSSFRow.CREATE_NULL_AS_BLANK).getCellType());
-        assertEquals(Cell.CELL_TYPE_BLANK,   row.getCell(3, XSSFRow.CREATE_NULL_AS_BLANK).getCellType());
-        assertEquals(Cell.CELL_TYPE_BLANK,   row.getCell(4, XSSFRow.CREATE_NULL_AS_BLANK).getCellType());
-        assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell(5, XSSFRow.CREATE_NULL_AS_BLANK).getCellType());
-
-        // Check created ones get the right column
-        assertEquals((short)0, row.getCell(0, XSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
-        assertEquals((short)1, row.getCell(1, XSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
-        assertEquals((short)2, row.getCell(2, XSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
-        assertEquals((short)3, row.getCell(3, XSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
-        assertEquals((short)4, row.getCell(4, XSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
-        assertEquals((short)5, row.getCell(5, XSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex());
+    @Override
+    protected XSSFITestDataProvider getTestDataProvider(){
+        return XSSFITestDataProvider.getInstance();
     }
 
-    /**
-     * Method that returns a row with some sample cells
-     * @return row
-     */
-    private static XSSFRow getSampleRow() {
-        XSSFSheet sheet = createParentObjects();
-        XSSFRow row = sheet.createRow(0);
-        row.createCell((short) 2);
-        row.createCell((short) 3, Cell.CELL_TYPE_NUMERIC);
-        row.createCell((short) 4);
-        row.createCell((short) 6);
-        row.createCell((short) 7);
-        row.createCell((short) 8);
-        row.createCell((short) 100);
-        return row;
+    public void testRowBounds() {
+        baseTestRowBounds(XSSFRow.MAX_ROW_NUMBER);
     }
 
-    private static XSSFSheet createParentObjects() {
-        XSSFWorkbook wb = new XSSFWorkbook();
-        return wb.createSheet();
-    }
-
-    /**
-     * Test that XSSFRow.getLastCellNum is consistent with HSSFRow.getLastCellNum
-     */
-    public void testLastCellNum() {
-        HSSFWorkbook wb1 = new HSSFWorkbook();
-        XSSFWorkbook wb2 = new XSSFWorkbook();
-
-        HSSFSheet sheet1 = wb1.createSheet();
-        XSSFSheet sheet2 = wb2.createSheet();
-
-        for (int i = 0; i < 10; i++) {
-            HSSFRow row1 = sheet1.createRow(i);
-            XSSFRow row2 = sheet2.createRow(i);
-
-            for (int j = 0; j < 5; j++) {
-                //before adding a cell
-                assertEquals(row1.getLastCellNum(), row2.getLastCellNum());
-
-                HSSFCell cell1 = row1.createCell(j);
-                XSSFCell cell2 = row2.createCell(j);
-
-                //after adding a cell
-                assertEquals(row1.getLastCellNum(), row2.getLastCellNum());
-            }
-        }
-    }
-
-    public void testRemoveCell() {
-        XSSFRow row = getSampleRow();
-
-        // Test removing the first cell
-        Cell firstCell = row.getCell((short) 2);
-        assertNotNull(firstCell);
-        assertEquals(7, row.getPhysicalNumberOfCells());
-        row.removeCell(firstCell);
-        assertEquals(6, row.getPhysicalNumberOfCells());
-        firstCell = row.getCell((short) 2);
-        assertNull(firstCell);
-
-        // Test removing the last cell
-        Cell lastCell = row.getCell((short) 100);
-        row.removeCell(lastCell);
-    }
-
-    public void testFirstLastCellNum() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFSheet sheet = workbook.createSheet();
-        XSSFRow 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());
-
-        workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
-        sheet = workbook.getSheetAt(0);
-
-        assertEquals(-1, sheet.getRow(0).getLastCellNum());
-        assertEquals(-1, sheet.getRow(0).getFirstCellNum());
-    }
-
-    public void testRowHeightCompatibility(){
-        Workbook wb1 = new HSSFWorkbook();
-        Workbook wb2 = new XSSFWorkbook();
-
-        Sheet sh1 = wb1.createSheet();
-        Sheet sh2 = wb2.createSheet();
-
-        sh2.setDefaultRowHeight(sh1.getDefaultRowHeight());
-
-        assertEquals(sh1.getDefaultRowHeight(), sh2.getDefaultRowHeight());
-
-        //junit.framework.AssertionFailedError: expected:<12.0> but was:<12.75>
-        //YK: there is a bug in HSSF version, it trunkates decimal part
-        //assertEquals(sh1.getDefaultRowHeightInPoints(), sh2.getDefaultRowHeightInPoints());
-
-        Row row1 = sh1.createRow(0);
-        Row row2 = sh2.createRow(0);
-
-        assertEquals(row1.getHeight(), row2.getHeight());
-        assertEquals(row1.getHeightInPoints(), row2.getHeightInPoints());
-        row1.setHeight((short)100);
-        row2.setHeight((short)100);
-        assertEquals(row1.getHeight(), row2.getHeight());
-        assertEquals(row1.getHeightInPoints(), row2.getHeightInPoints());
-
-        row1.setHeightInPoints(25.5f);
-        row2.setHeightInPoints(25.5f);
-        assertEquals(row1.getHeight(), row2.getHeight());
-        assertEquals(row1.getHeightInPoints(), row2.getHeightInPoints());
-
-
+    public void testCellBounds() {
+        baseTestCellBounds(XSSFCell.LAST_COLUMN_NUMBER);
     }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java?rev=759112&r1=759111&r2=759112&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java Fri Mar 27 11:50:52 2009
@@ -20,124 +20,36 @@
 import java.io.File;
 import java.util.Iterator;
 import junit.framework.TestCase;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.xssf.model.CommentsTable;
 import org.apache.poi.xssf.model.StylesTable;
 import org.apache.poi.xssf.model.CalculationChain;
 import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
 import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
 
 
-public class TestXSSFSheet extends TestCase {
+public class TestXSSFSheet extends BaseTestSheet {
 
-    public void testRowIterator() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-        Row row1 = sheet.createRow(0);
-        Row row2 = sheet.createRow(1);
-        Iterator<Row> it = sheet.rowIterator();
-        assertNotNull(it);
-        assertTrue(it.hasNext());
-        assertEquals(row1, it.next());
-        assertTrue(it.hasNext());
-        assertEquals(row2, it.next());
-        assertFalse(it.hasNext());
+    @Override
+    protected XSSFITestDataProvider getTestDataProvider(){
+        return XSSFITestDataProvider.getInstance();
     }
 
-    public void testGetRow() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-        Row row1 = sheet.createRow(0);
-        Cell cell = row1.createCell((short) 0);
-        cell.setCellType(Cell.CELL_TYPE_NUMERIC);
-        cell.setCellValue((double) 1000);
-
-        // Test getting a row and check its cell's value
-        Row row_got = sheet.getRow(0);
-        Cell cell_got = row_got.getCell((short) 0);
-        assertEquals((double) 1000, cell_got.getNumericCellValue());
+    //TODO column styles are not yet supported by XSSF
+    public void testDefaultColumnStyle() {
+        //super.testDefaultColumnStyle();
     }
 
-    public void testCreateRow() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-
-        // Test row creation with consecutive indexes
-        Row row1 = sheet.createRow(0);
-        Row row2 = sheet.createRow(1);
-        assertEquals(0, row1.getRowNum());
-        assertEquals(1, row2.getRowNum());
-        Iterator<Row> it = sheet.rowIterator();
-        assertTrue(it.hasNext());
-        assertEquals(row1, it.next());
-        assertTrue(it.hasNext());
-        assertEquals(row2, it.next());
-
-        // Test row creation with non consecutive index
-        Row row101 = sheet.createRow(100);
-        assertNotNull(row101);
-
-        // Test overwriting an existing row
-        Row row2_ovrewritten = sheet.createRow(1);
-        Cell cell = row2_ovrewritten.createCell((short) 0);
-        cell.setCellType(Cell.CELL_TYPE_NUMERIC);
-        cell.setCellValue((double) 100);
-        Iterator<Row> it2 = sheet.rowIterator();
-        assertTrue(it2.hasNext());
-        assertEquals(row1, it2.next());
-        assertTrue(it2.hasNext());
-        Row row2_overwritten_copy = it2.next();
-        assertEquals(row2_ovrewritten, row2_overwritten_copy);
-        assertEquals(row2_overwritten_copy.getCell((short) 0).getNumericCellValue(), (double) 100);
-    }
-
-    public void testRemoveRow() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-        Row row1 = sheet.createRow(1);
-        Row row2 = sheet.createRow(2);
-        assertNotNull(sheet.getRow(1));
-        sheet.removeRow(row2);
-        assertNull(sheet.getRow(0));
-        assertNull(sheet.getRow(2));
-        assertNotNull(sheet.getRow(1));
-    }
-
-    public void testGetSetDefaultRowHeight() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-        // Test that default height set by the constructor
-        assertEquals((short) 300, sheet.getDefaultRowHeight());
-        assertEquals((float) 15, sheet.getDefaultRowHeightInPoints());
-        // Set a new default row height in twips and test getting the value in points
-        sheet.setDefaultRowHeight((short) 360);
-        assertEquals((float) 18, sheet.getDefaultRowHeightInPoints());
-        // Test that defaultRowHeight is a truncated short: E.G. 360inPoints -> 18; 361inPoints -> 18
-        sheet.setDefaultRowHeight((short) 361);
-        assertEquals((float)361/20, sheet.getDefaultRowHeightInPoints());
-        // Set a new default row height in points and test getting the value in twips
-        sheet.setDefaultRowHeightInPoints((short) 17);
-        assertEquals((short) 340, sheet.getDefaultRowHeight());
-    }
-
-    public void testGetSetDefaultColumnWidth() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-        // Test that default column width set by the constructor
-        assertEquals((short) 8, sheet.getDefaultColumnWidth());
-        // Set a new default column width and get its value
-        sheet.setDefaultColumnWidth((short) 14);
-        assertEquals((short) 14, sheet.getDefaultColumnWidth());
+    public void testTestGetSetMargin() {
+        baseTestGetSetMargin(new double[]{0.7, 0.7, 0.75, 0.75, 0.3, 0.3});
     }
 
     public void testGetFirstLastRowNum() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
+        Workbook workbook = getTestDataProvider().createWorkbook();
         Sheet sheet = workbook.createSheet("Sheet 1");
         Row row10 = sheet.createRow(9);
         Row row1 = sheet.createRow(0);
@@ -146,149 +58,8 @@
         assertEquals(9, sheet.getLastRowNum());
     }
 
-    public void testGetPhysicalNumberOfRows() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-        Row row10 = sheet.createRow(9);
-        Row row1 = sheet.createRow(0);
-        Row row2 = sheet.createRow(1);
-        assertEquals(3, sheet.getPhysicalNumberOfRows());
-    }
-
-    public void testGetSetRowBreaks() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-        assertEquals(0, sheet.getRowBreaks().length);
-        sheet.setRowBreak(1);
-        sheet.setRowBreak(15);
-        assertNotNull(sheet.getRowBreaks());
-        assertEquals(1, sheet.getRowBreaks()[0]);
-        assertEquals(15, sheet.getRowBreaks()[1]);
-        sheet.setRowBreak(1);
-        assertEquals(2, sheet.getRowBreaks().length);
-    }
-
-    public void testRemoveRowBreak() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-        sheet.setRowBreak(1);
-        assertEquals(1, sheet.getRowBreaks().length);
-        sheet.setRowBreak(2);
-        assertEquals(2, sheet.getRowBreaks().length);
-        sheet.removeRowBreak(1);
-        assertEquals(1, sheet.getRowBreaks().length);
-    }
-
-    public void testMaxColumnWidth() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-        sheet.setColumnWidth(0, 255*256); //the limit
-        try {
-            sheet.setColumnWidth(0, 256*256); //the limit
-            fail("expected exception");
-        } catch (Exception e){
-            ;
-        }
-    }
-
-    public void testGetSetColumnBreaks() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-        assertEquals(0, sheet.getColumnBreaks().length);
-        sheet.setColumnBreak((short) 11);
-        assertNotNull(sheet.getColumnBreaks());
-        assertEquals(11, sheet.getColumnBreaks()[0]);
-        sheet.setColumnBreak((short) 11223);
-        assertEquals(2, sheet.getColumnBreaks().length);
-    }
-
-    public void testRemoveColumnBreak() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-        assertEquals(0, sheet.getColumnBreaks().length);
-        sheet.setColumnBreak((short) 11);
-        assertNotNull(sheet.getColumnBreaks());
-        sheet.setColumnBreak((short) 12);
-        assertEquals(2, sheet.getColumnBreaks().length);
-        sheet.removeColumnBreak((short) 11);
-        assertEquals(1, sheet.getColumnBreaks().length);
-        sheet.removeColumnBreak((short) 15);
-        assertEquals(1, sheet.getColumnBreaks().length);
-    }
-
-    public void testIsRowColumnBroken() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-        assertFalse(sheet.isRowBroken(0));
-        sheet.setRowBreak(3);
-        assertTrue(sheet.isRowBroken(3));
-        assertFalse(sheet.isColumnBroken((short) 0));
-        sheet.setColumnBreak((short) 3);
-        assertTrue(sheet.isColumnBroken((short) 3));
-    }
-
-    public void testGetSetAutoBreaks() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-        assertTrue(sheet.getAutobreaks());
-        sheet.setAutobreaks(false);
-        assertFalse(sheet.getAutobreaks());
-    }
-
-    public void testIsSetFitToPage() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-        assertFalse(sheet.getFitToPage());
-        sheet.setFitToPage(true);
-        assertTrue(sheet.getFitToPage());
-        sheet.setFitToPage(false);
-        assertFalse(sheet.getFitToPage());
-    }
-
-    public void testGetSetMargin() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-        assertEquals(0.7, sheet.getMargin((short) 0));
-        sheet.setMargin((short) 0, 10);
-        assertEquals((double) 10, sheet.getMargin((short) 0));
-        assertEquals((double) 10, sheet.getMargin((short) 1));
-        assertEquals((double) 10, sheet.getMargin((short) 2));
-        assertEquals((double) 10, sheet.getMargin((short) 3));
-        assertEquals((double) 10, sheet.getMargin((short) 4));
-        assertEquals((double) 10, sheet.getMargin((short) 5));
-        sheet.setMargin((short) 1, 11);
-        assertEquals((double) 11, sheet.getMargin((short) 1));
-        assertEquals((double) 11, sheet.getMargin((short) 2));
-        assertEquals((double) 11, sheet.getMargin((short) 3));
-        assertEquals((double) 11, sheet.getMargin((short) 4));
-        assertEquals((double) 11, sheet.getMargin((short) 5));
-        sheet.setMargin((short) 2, 12);
-        assertEquals((double) 12, sheet.getMargin((short) 2));
-        assertEquals((double) 12, sheet.getMargin((short) 3));
-        assertEquals((double) 12, sheet.getMargin((short) 4));
-        assertEquals((double) 12, sheet.getMargin((short) 5));
-        sheet.setMargin((short) 3, 13);
-        assertEquals((double) 13, sheet.getMargin((short) 3));
-        assertEquals((double) 13, sheet.getMargin((short) 4));
-        assertEquals((double) 13, sheet.getMargin((short) 5));
-        sheet.setMargin((short) 4, 14);
-        assertEquals((double) 14, sheet.getMargin((short) 4));
-        assertEquals((double) 14, sheet.getMargin((short) 5));
-        sheet.setMargin((short) 5, 15);
-        assertEquals((double) 15, sheet.getMargin((short) 5));
-
-        // Test that nothing happens if another margin constant is given (E.G. 65)
-        sheet.setMargin((short) 65, 15);
-        assertEquals((double) 10, sheet.getMargin((short) 0));
-        assertEquals((double) 11, sheet.getMargin((short) 1));
-        assertEquals((double) 12, sheet.getMargin((short) 2));
-        assertEquals((double) 13, sheet.getMargin((short) 3));
-        assertEquals((double) 14, sheet.getMargin((short) 4));
-        assertEquals((double) 15, sheet.getMargin((short) 5));
-    }
-
     public void testGetFooter() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
+        XSSFWorkbook workbook = getTestDataProvider().createWorkbook();
         XSSFSheet sheet = workbook.createSheet("Sheet 1");
         assertNotNull(sheet.getFooter());
         sheet.getFooter().setCenter("test center footer");
@@ -364,7 +135,7 @@
     }
 
     public void testGetAllHeadersFooters() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
+        XSSFWorkbook workbook = getTestDataProvider().createWorkbook();
         XSSFSheet sheet = workbook.createSheet("Sheet 1");
         assertNotNull(sheet.getOddFooter());
         assertNotNull(sheet.getEvenFooter());
@@ -402,50 +173,8 @@
         assertEquals("odd header center", sheet.getHeader().getCenter());
     }
 
-    public void testGetSetColumnWidth() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFSheet sheet = workbook.createSheet("Sheet 1");
-        sheet.setColumnWidth(1,  22*256);
-        assertEquals(22*256, sheet.getColumnWidth(1));
-
-        // Now check the low level stuff, and check that's all
-        //  been set correctly
-        XSSFSheet xs = sheet;
-        CTWorksheet cts = xs.getCTWorksheet();
-
-        CTCols[] cols_s = cts.getColsArray();
-        assertEquals(1, cols_s.length);
-        CTCols cols = cols_s[0];
-        assertEquals(1, cols.sizeOfColArray());
-        CTCol col = cols.getColArray(0);
-
-        // XML is 1 based, POI is 0 based
-        assertEquals(2, col.getMin());
-        assertEquals(2, col.getMax());
-        assertEquals(22.0, col.getWidth());
-
-
-        // Now set another
-        sheet.setColumnWidth(3, 33*256);
-
-        cols_s = cts.getColsArray();
-        assertEquals(1, cols_s.length);
-        cols = cols_s[0];
-        assertEquals(2, cols.sizeOfColArray());
-
-        col = cols.getColArray(0);
-        assertEquals(2, col.getMin()); // POI 1
-        assertEquals(2, col.getMax());
-        assertEquals(22.0, col.getWidth());
-
-        col = cols.getColArray(1);
-        assertEquals(4, col.getMin()); // POI 3
-        assertEquals(4, col.getMax());
-        assertEquals(33.0, col.getWidth());
-    }
-
     public void testGetSetColumnHidden() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
+        Workbook workbook = getTestDataProvider().createWorkbook();
         Sheet sheet = workbook.createSheet("Sheet 1");
         sheet.setColumnHidden((short) 2, true);
         assertTrue(sheet.isColumnHidden((short) 2));
@@ -463,185 +192,6 @@
         assertTrue(col.getBestFit());
     }
     
-    public void testGetSetHorizontallyCentered() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFSheet sheet = workbook.createSheet("Sheet 1");
-        assertFalse(sheet.getHorizontallyCenter());
-        sheet.setHorizontallyCenter(true);
-        assertTrue(sheet.getHorizontallyCenter());
-        sheet.setHorizontallyCenter(false);
-        assertFalse(sheet.getHorizontallyCenter());
-    }
-    
-    public void testGetSetVerticallyCentered() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFSheet sheet = workbook.createSheet("Sheet 1");
-        assertFalse(sheet.getVerticallyCenter());
-        sheet.setVerticallyCenter(true);
-        assertTrue(sheet.getVerticallyCenter());
-        sheet.setVerticallyCenter(false);
-        assertFalse(sheet.getVerticallyCenter());
-    }
-    
-    public void testIsSetPrintGridlines() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFSheet sheet = workbook.createSheet("Sheet 1");
-        assertFalse(sheet.isPrintGridlines());
-        sheet.setPrintGridlines(true);
-        assertTrue(sheet.isPrintGridlines());
-    }
-    
-    public void testIsSetDisplayFormulas() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFSheet sheet = workbook.createSheet("Sheet 1");
-        assertFalse(sheet.isDisplayFormulas());
-        sheet.setDisplayFormulas(true);
-        assertTrue(sheet.isDisplayFormulas());
-    }
-    
-    public void testIsSetDisplayGridLines() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFSheet sheet = workbook.createSheet("Sheet 1");
-        assertTrue(sheet.isDisplayGridlines());
-        sheet.setDisplayGridlines(false);
-        assertFalse(sheet.isDisplayGridlines());
-    }
-    
-    public void testIsSetDisplayGuts() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFSheet sheet = workbook.createSheet("Sheet 1");
-        assertTrue(sheet.getDisplayGuts());
-        sheet.setDisplayGuts(false);
-        assertFalse(sheet.getDisplayGuts());
-    }
-    
-    public void testIsSetDisplayRowColHeadings() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFSheet sheet = workbook.createSheet("Sheet 1");
-        assertTrue(sheet.isDisplayRowColHeadings());
-        sheet.setDisplayRowColHeadings(false);
-        assertFalse(sheet.isDisplayRowColHeadings());
-    }
-    
-    public void testGetScenarioProtect() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFSheet sheet = workbook.createSheet("Sheet 1");
-        assertFalse(sheet.getScenarioProtect());
-    }
-  /*  
-    public void testTopRowLeftCol() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFSheet sheet = workbook.createSheet("Sheet 1");
-        sheet.showInPane((short)1, (short)1);
-        assertEquals((short) 1, sheet.getTopRow());
-        assertEquals((short) 1, sheet.getLeftCol());
-        sheet.showInPane((short)2, (short)26);
-        assertEquals((short) 2, sheet.getTopRow());
-        assertEquals((short) 26, sheet.getLeftCol());
-    }
-    */
-    public void testShiftRows() {
-        XSSFWorkbook workbook = new XSSFWorkbook();
-        
-        XSSFSheet sheet = createSheet(workbook, "Sheet 1");
-    	sheet.shiftRows(1, 2, 4, true, false);
-    	assertEquals((short) 1, sheet.getRow(5).getHeight());
-    	assertEquals((short) 2, sheet.getRow(6).getHeight());
-    	assertNull(sheet.getRow(1));
-    	assertNull(sheet.getRow(2));
-    	assertEquals(8, sheet.getPhysicalNumberOfRows());
-
-        XSSFSheet sheet2 = createSheet(workbook, "Sheet 2");
-    	sheet2.shiftRows(1, 5, 3, true, false);
-    	assertEquals((short) 1, sheet2.getRow(4).getHeight());
-    	assertEquals((short) 2, sheet2.getRow(5).getHeight());
-    	assertEquals((short) 3, sheet2.getRow(6).getHeight());
-    	assertEquals((short) 4, sheet2.getRow(7).getHeight());
-    	assertEquals((short) 5, sheet2.getRow(8).getHeight());
-    	assertNull(sheet2.getRow(1));
-    	assertNull(sheet2.getRow(2));
-    	assertNull(sheet2.getRow(3));
-    	assertEquals(7, sheet2.getPhysicalNumberOfRows());
-
-        XSSFSheet sheet3 = createSheet(workbook, "Sheet 3");
-    	sheet3.shiftRows(5, 7, -3, true, false);
-    	assertEquals(5, sheet3.getRow(2).getHeight());
-    	assertEquals(6, sheet3.getRow(3).getHeight());
-    	assertEquals(7, sheet3.getRow(4).getHeight());
-    	assertNull(sheet3.getRow(5));
-    	assertNull(sheet3.getRow(6));
-    	assertNull(sheet3.getRow(7));
-    	assertEquals(7, sheet3.getPhysicalNumberOfRows());
-
-        XSSFSheet sheet4 = createSheet(workbook, "Sheet 4");
-    	sheet4.shiftRows(5, 7, -2, true, false);
-    	assertEquals(5, sheet4.getRow(3).getHeight());
-    	assertEquals(6, sheet4.getRow(4).getHeight());
-    	assertEquals(7, sheet4.getRow(5).getHeight());
-    	assertNull(sheet4.getRow(6));
-    	assertNull(sheet4.getRow(7));
-    	assertEquals(8, sheet4.getPhysicalNumberOfRows());
-
-    	// Test without copying rowHeight
-        XSSFSheet sheet5 = createSheet(workbook, "Sheet 5");
-    	sheet5.shiftRows(5, 7, -2, false, false);
-    	assertEquals(sheet5.getDefaultRowHeight(), sheet5.getRow(3).getHeight());
-    	assertEquals(sheet5.getDefaultRowHeight(), sheet5.getRow(4).getHeight());
-    	assertEquals(sheet5.getDefaultRowHeight(), sheet5.getRow(5).getHeight());
-    	assertNull(sheet5.getRow(6));
-    	assertNull(sheet5.getRow(7));
-    	assertEquals(8, sheet5.getPhysicalNumberOfRows());
-
-    	// Test without copying rowHeight and resetting to default height
-        XSSFSheet sheet6 = createSheet(workbook, "Sheet 6");
-        sheet6.setDefaultRowHeight((short) 200);
-    	sheet6.shiftRows(5, 7, -2, false, true);
-    	assertEquals(200, sheet6.getRow(3).getHeight());
-    	assertEquals(200, sheet6.getRow(4).getHeight());
-    	assertEquals(200, sheet6.getRow(5).getHeight());
-    	assertNull(sheet6.getRow(6));
-    	assertNull(sheet6.getRow(7));
-    	assertEquals(8, sheet6.getPhysicalNumberOfRows());
-    }
-
-    /**
-     * When shifting rows, update formulas on that sheet to point to the new location of those rows
-     * (see bugzilla 46536)
-     */
-    public void testShiftRows_46536() {
-        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("46536.xlsx");
-        CalculationChain calcChain = wb.getCalculationChain();
-        int numItems = calcChain.getCTCalcChain().getCArray().length;
-        assertEquals(3, numItems);
-
-        XSSFSheet sheet = wb.getSheet("Test");
-        XSSFRow row2 = sheet.getRow(1);
-        XSSFCell cell_A2 = row2.getCell(0);
-        assertEquals("A2", cell_A2.getReference());
-
-        XSSFRow row3 = sheet.getRow(2);
-        XSSFCell cell_B3 = row3.getCell(1);
-        assertEquals("B3", cell_B3.getReference());
-
-        XSSFCell cell_E2 = row2.getCell(4);
-        CTCellFormula f = cell_E2.getCTCell().getF();
-        assertEquals("B2+C2+D2", f.getStringValue());
-        assertEquals("E2:E3", f.getRef());
-
-        sheet.shiftRows(1, sheet.getLastRowNum(), 3, false, true);
-
-        assertEquals(4, row2.getRowNum());
-        assertEquals(5, row3.getRowNum());
-        assertEquals("A5", cell_A2.getReference());
-        assertEquals("B6", cell_B3.getReference());
-
-        assertEquals("B5+C5+D5", f.getStringValue());
-        assertEquals("E5:E6", f.getRef());
-
-        numItems = calcChain.getCTCalcChain().getCArray().length;
-        assertEquals(1, numItems);
-
-    }
 
     public void testGetCellComment() {
         XSSFWorkbook workbook = new XSSFWorkbook();
@@ -758,31 +308,7 @@
     }
     
 
-	private XSSFSheet createSheet(XSSFWorkbook workbook, String name) {
-        XSSFSheet sheet = workbook.createSheet(name);
-    	Row row0 = sheet.createRow(0);
-    	row0.setHeight((short) 1);
-    	Row row1 = sheet.createRow(1);
-    	row1.setHeight((short) 1);
-    	Row row2 = sheet.createRow(2);
-    	row2.setHeight((short) 2);
-    	Row row3 = sheet.createRow(3);
-    	row3.setHeight((short) 3);
-    	Row row4 = sheet.createRow(4);
-    	row4.setHeight((short) 4);
-    	Row row5 = sheet.createRow(5);
-    	row5.setHeight((short) 5);
-    	Row row6 = sheet.createRow(6);
-    	row6.setHeight((short) 6);
-    	Row row7 = sheet.createRow(7);
-    	row7.setHeight((short) 7);
-    	Row row8 = sheet.createRow(8);
-    	row8.setHeight((short) 8);
-    	Row row9 = sheet.createRow(9);
-    	row9.setHeight((short) 9);
-    	return sheet;
-	}
-	
+
 	
 	
 	   public void testGroupUngroupColumn() {
@@ -881,77 +407,49 @@
         }
     }
 
-    public void testOutlineProperties() {
-        XSSFWorkbook wb = new XSSFWorkbook();
+    /**
+     * Get / Set column width and check the actual values of the underlying XML beans
+     */
+    public void testColumnWidth_lowlevel() {
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        XSSFSheet sheet = workbook.createSheet("Sheet 1");
+        sheet.setColumnWidth(1,  22*256);
+        assertEquals(22*256, sheet.getColumnWidth(1));
 
-        XSSFSheet sheet = wb.createSheet();
+        // Now check the low level stuff, and check that's all
+        //  been set correctly
+        XSSFSheet xs = sheet;
+        CTWorksheet cts = xs.getCTWorksheet();
 
-        assertTrue(sheet.getRowSumsBelow());
-        assertTrue(sheet.getRowSumsRight());
+        CTCols[] cols_s = cts.getColsArray();
+        assertEquals(1, cols_s.length);
+        CTCols cols = cols_s[0];
+        assertEquals(1, cols.sizeOfColArray());
+        CTCol col = cols.getColArray(0);
 
-        sheet.setRowSumsBelow(false);
-        sheet.setRowSumsRight(false);
+        // XML is 1 based, POI is 0 based
+        assertEquals(2, col.getMin());
+        assertEquals(2, col.getMax());
+        assertEquals(22.0, col.getWidth());
 
-        assertFalse(sheet.getRowSumsBelow());
-        assertFalse(sheet.getRowSumsRight());
-    }
 
+        // Now set another
+        sheet.setColumnWidth(3, 33*256);
 
-    public void testSetColumnGroupCollapsed(){
-	
-    }
-    
+        cols_s = cts.getColsArray();
+        assertEquals(1, cols_s.length);
+        cols = cols_s[0];
+        assertEquals(2, cols.sizeOfColArray());
 
-    public void testColumnWidthCompatibility() {
-        Workbook wb1 = new HSSFWorkbook();
-        Workbook wb2 = new XSSFWorkbook();
-
-        Sheet sh1 = wb1.createSheet();
-        Sheet sh2 = wb2.createSheet();
-
-        assertEquals(sh1.getDefaultColumnWidth(), sh2.getDefaultColumnWidth());
-
-        //if column width is not set, HSSF returns a wrong value which does not take into account
-        //margins and borders, it is always less than the actual column width
-        assertEquals(2048, sh1.getColumnWidth(0));
-        assertEquals(2340, sh2.getColumnWidth(0));
-
-        sh1.setDefaultColumnWidth(1000);
-        sh2.setDefaultColumnWidth(1000);
-        assertEquals(1000, sh2.getDefaultColumnWidth());
-        assertEquals(sh1.getDefaultColumnWidth(), sh2.getDefaultColumnWidth());
-
-        sh1.setColumnWidth(0, 500);
-        sh2.setColumnWidth(0, 500);
-        assertEquals(500, sh2.getColumnWidth(0));
-        assertEquals(sh1.getColumnWidth(0), sh2.getColumnWidth(0));
-    }
+        col = cols.getColArray(0);
+        assertEquals(2, col.getMin()); // POI 1
+        assertEquals(2, col.getMax());
+        assertEquals(22.0, col.getWidth());
 
-    /**
-     * Tests the display of gridlines, formulas, and rowcolheadings.
-     * @author Shawn Laubach (slaubach at apache dot org)
-     */
-    public void testDisplayOptions() {
-        Workbook wb = new XSSFWorkbook();
-        Sheet 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 = XSSFTestDataSamples.writeOutAndReadBack(wb);
-        sheet = wb.getSheetAt(0);
-
-        assertEquals(sheet.isDisplayGridlines(), false);
-        assertEquals(sheet.isDisplayRowColHeadings(), false);
-        assertEquals(sheet.isDisplayFormulas(), true);
-        assertEquals(sheet.isDisplayZeros(), false);
+        col = cols.getColArray(1);
+        assertEquals(4, col.getMin()); // POI 3
+        assertEquals(4, col.getMax());
+        assertEquals(33.0, col.getWidth());
     }
 
 }



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


Mime
View raw message