]> source.dussan.org Git - poi.git/commitdiff
Follow up fix after r644473 (bug 44739) TestHSSFConditionalFormatting had a bug and...
authorJosh Micich <josh@apache.org>
Thu, 3 Apr 2008 21:17:26 +0000 (21:17 +0000)
committerJosh Micich <josh@apache.org>
Thu, 3 Apr 2008 21:17:26 +0000 (21:17 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@644509 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/cf/CellRange.java
src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConfditionalFormatting.java [deleted file]

index f8839d99c1adff5013b24b0ceda338720c33ac5f..f45b79b003a88c86a513334731ea2c8f3863ae98 100644 (file)
@@ -78,8 +78,8 @@ public final class CellRange
                return _firstColumn == 0 && _lastColumn == LAST_COLUMN_INDEX;
        }
        
-       public CellRange(Region r) {
-               this(r.getRowFrom(), r.getRowTo(), r.getColumnFrom(), r.getColumnTo());
+       private static CellRange createFromRegion(Region r) {
+               return new CellRange(r.getRowFrom(), r.getRowTo(), r.getColumnFrom(), r.getColumnTo());
        }
 
        private static boolean isValid(int firstRow, int lastRow, int firstColumn, int lastColumn)
@@ -358,7 +358,7 @@ public final class CellRange
                CellRange[] result = new CellRange[regions.length];
                for( int i=0; i<regions.length; i++)
                {
-                       result[i] = new CellRange(regions[i]);
+                       result[i] = createFromRegion(regions[i]);
                }
                return result;
        }
index cbc555da36abda243b5c6b589c54793b7c9c152a..6d6b053a63d8f1e23f9c5d1d9abe4392344fd543 100755 (executable)
@@ -40,6 +40,7 @@ public class AllUserModelTests {
                result.addTestSuite(TestFormulas.class);
                result.addTestSuite(TestHSSFCell.class);
                result.addTestSuite(TestHSSFClientAnchor.class);
+               result.addTestSuite(TestHSSFConditionalFormatting.class);
                result.addTestSuite(TestHSSFComment.class);
                result.addTestSuite(TestHSSFDateUtil.class);
                result.addTestSuite(TestHSSFHeaderFooter.class);
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
new file mode 100644 (file)
index 0000000..5dcc61a
--- /dev/null
@@ -0,0 +1,90 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.usermodel;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.hssf.util.Region;
+/**
+ * 
+ * @author Dmitriy Kumshayev
+ */
+public final class TestHSSFConditionalFormatting extends TestCase
+{
+       public void testLastAndFirstColumns() 
+       {
+               HSSFWorkbook workbook = new HSSFWorkbook();
+               HSSFSheet sheet = workbook.createSheet();
+               String formula = "7";
+
+               HSSFFontFormatting fontFmt = new HSSFFontFormatting();
+               fontFmt.setFontStyle(true, false);
+
+               HSSFBorderFormatting bordFmt = new HSSFBorderFormatting();
+               bordFmt.setBorderBottom(HSSFBorderFormatting.BORDER_THIN);
+               bordFmt.setBorderTop(HSSFBorderFormatting.BORDER_THICK);
+               bordFmt.setBorderLeft(HSSFBorderFormatting.BORDER_DASHED);
+               bordFmt.setBorderRight(HSSFBorderFormatting.BORDER_DOTTED);
+
+               HSSFPatternFormatting patternFmt = new HSSFPatternFormatting();
+               patternFmt.setFillBackgroundColor(HSSFColor.RED.index);
+
+               HSSFConditionalFormattingRule [] cfRules =
+               {
+                       sheet.createConditionalFormattingRule(formula, fontFmt, bordFmt, patternFmt),
+                       sheet.createConditionalFormattingRule(ComparisonOperator.BETWEEN, "1", "2", fontFmt, bordFmt, patternFmt)
+               };
+
+               short col = 1;
+               Region [] regions =
+               {
+                       new Region(0,col,65535,col)
+               };
+
+               sheet.addConditionalFormatting(regions, cfRules);
+               sheet.addConditionalFormatting(regions, cfRules);
+
+               // Verification
+               assertEquals(2, sheet.getNumConditionalFormattings());
+               sheet.removeConditionalFormatting(1);
+               assertEquals(1, sheet.getNumConditionalFormattings());
+               HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(0);
+               assertNotNull(cf);
+
+               regions = cf.getFormattingRegions();
+               assertNotNull(regions);
+               assertEquals(1, regions.length);
+               Region r = regions[0];
+               assertEquals(1, r.getColumnFrom());
+               assertEquals(1, r.getColumnTo());
+               assertEquals(0, r.getRowFrom());
+               assertEquals(65535, r.getRowTo());
+
+               assertEquals(2, cf.getNumberOfRules());
+
+               HSSFConditionalFormattingRule rule1 = cf.getRule(0);
+               assertEquals("7",rule1.getFormula1()); 
+               assertNull(rule1.getFormula2());
+
+               HSSFConditionalFormattingRule rule2 = cf.getRule(1);
+               assertEquals("2",rule2.getFormula2()); 
+               assertEquals("1",rule2.getFormula1()); 
+       }
+}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConfditionalFormatting.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConfditionalFormatting.java
deleted file mode 100644 (file)
index 6186d22..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hssf.usermodel;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator;
-import org.apache.poi.hssf.util.HSSFColor;
-import org.apache.poi.hssf.util.Region;
-/**
- * 
- * @author Dmitriy Kumshayev
- */
-public final class TestHSSFConfditionalFormatting extends TestCase
-{
-       public void testLastAndFirstColumns() 
-       {
-               HSSFWorkbook workbook = new HSSFWorkbook();
-               HSSFSheet sheet = workbook.createSheet();
-               String formula = "7";
-
-               HSSFFontFormatting fontFmt = new HSSFFontFormatting();
-               fontFmt.setFontStyle(true, false);
-
-               HSSFBorderFormatting bordFmt = new HSSFBorderFormatting();
-               bordFmt.setBorderBottom(HSSFBorderFormatting.BORDER_THIN);
-               bordFmt.setBorderTop(HSSFBorderFormatting.BORDER_THICK);
-               bordFmt.setBorderLeft(HSSFBorderFormatting.BORDER_DASHED);
-               bordFmt.setBorderRight(HSSFBorderFormatting.BORDER_DOTTED);
-
-               HSSFPatternFormatting patternFmt = new HSSFPatternFormatting();
-               patternFmt.setFillBackgroundColor(HSSFColor.RED.index);
-
-               HSSFConditionalFormattingRule [] cfRules =
-               {
-                       sheet.createConditionalFormattingRule(formula, fontFmt, bordFmt, patternFmt),
-                       sheet.createConditionalFormattingRule(ComparisonOperator.BETWEEN, "1", "2", fontFmt, bordFmt, patternFmt)
-               };
-
-               short col = 1;
-               Region [] regions =
-               {
-                       new Region(0,col,-1,col)
-               };
-
-               sheet.addConditionalFormatting(regions, cfRules);
-               sheet.addConditionalFormatting(regions, cfRules);
-
-               // Verification
-               assertEquals(2, sheet.getNumConditionalFormattings());
-               sheet.removeConditionalFormatting(1);
-               assertEquals(1, sheet.getNumConditionalFormattings());
-               HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(0);
-               assertNotNull(cf);
-
-               regions = cf.getFormattingRegions();
-               assertNotNull(regions);
-               assertEquals(1, regions.length);
-               Region r = regions[0];
-               assertEquals(1, r.getColumnFrom());
-               assertEquals(1, r.getColumnTo());
-               assertEquals(0, r.getRowFrom());
-               assertEquals(-1, r.getRowTo());
-
-               assertEquals(2, cf.getNumberOfRules());
-
-               HSSFConditionalFormattingRule rule1 = cf.getRule(0);
-               assertEquals("7",rule1.getFormula1()); 
-               assertNull(rule1.getFormula2());
-
-               HSSFConditionalFormattingRule rule2 = cf.getRule(1);
-               assertEquals("2",rule2.getFormula2()); 
-               assertEquals("1",rule2.getFormula1()); 
-       }
-}