]> source.dussan.org Git - poi.git/commitdiff
Move some test checks to using ConditionType instead of raw bytes
authorNick Burch <nick@apache.org>
Mon, 13 Jul 2015 20:11:47 +0000 (20:11 +0000)
committerNick Burch <nick@apache.org>
Mon, 13 Jul 2015 20:11:47 +0000 (20:11 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1690808 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java
src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java

index dbfa49cabec29bd9d91b8c7686cf3194c89014ec..88a9d50e31b88a304cc5f3a892a4defa8fbc8825 100644 (file)
@@ -81,6 +81,8 @@ public final class HSSFConditionalFormatting  implements ConditionalFormatting
        // TODO Should this be assigning unique IDs to the rules
        //  as they get added to the file?
        
+    // TODO Support types beyond CELL_VALUE_IS and FORMULA
+
        HSSFConditionalFormatting(HSSFWorkbook workbook, CFRecordsAggregate cfAggregate)
        {
                if(workbook == null) {
index 0b4a05d096efd20f0c9e7e71ae358de30c25073c..92b91ceeb56ecca2c8bffd205074aa89e90efc77 100644 (file)
@@ -34,7 +34,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;\r
 \r
 /**\r
- * @author Yegor Kozlov\r
+ * XSSF suport for Conditional Formatting rules\r
  */\r
 public class XSSFConditionalFormattingRule implements ConditionalFormattingRule {\r
     private final CTCfRule _cfRule;\r
@@ -63,6 +63,8 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
         typeLookup.put(STCfType.TIME_PERIOD, ConditionType.FILTER);\r
         typeLookup.put(STCfType.ABOVE_AVERAGE, ConditionType.FILTER);\r
     }\r
+    \r
+    // TODO Support types beyond CELL_VALUE_IS and FORMULA\r
 \r
     /*package*/ XSSFConditionalFormattingRule(XSSFSheet sh){\r
         _cfRule = CTCfRule.Factory.newInstance();\r
index 902a0131224fb12914062da66cad4a72881d9a13..ff5d58903614a82ad2bcd9d7a3b4f73918a64c4c 100644 (file)
@@ -102,7 +102,8 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
         SheetConditionalFormatting sheetCF = sh.getSheetConditionalFormatting();\r
 \r
         ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule("SUM(A1:A5)>10");\r
-        assertEquals(ConditionalFormattingRule.CONDITION_TYPE_FORMULA, rule1.getConditionType());\r
+        assertEquals(ConditionType.FORMULA.id, rule1.getConditionType());\r
+        assertEquals(ConditionType.FORMULA, rule1.getConditionTypeType());\r
         assertEquals("SUM(A1:A5)>10", rule1.getFormula1());\r
         int formatIndex1 = sheetCF.addConditionalFormatting(\r
                 new CellRangeAddress[]{\r
@@ -137,56 +138,65 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
 \r
         ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(\r
                 ComparisonOperator.EQUAL, "SUM(A1:A5)+10");\r
-        assertEquals(ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS, rule1.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS.id, rule1.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS, rule1.getConditionTypeType());\r
         assertEquals("SUM(A1:A5)+10", rule1.getFormula1());\r
         assertEquals(ComparisonOperator.EQUAL, rule1.getComparisonOperation());\r
 \r
         ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule(\r
                 ComparisonOperator.NOT_EQUAL, "15");\r
-        assertEquals(ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS, rule2.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS.id, rule2.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS, rule2.getConditionTypeType());\r
         assertEquals("15", rule2.getFormula1());\r
         assertEquals(ComparisonOperator.NOT_EQUAL, rule2.getComparisonOperation());\r
 \r
         ConditionalFormattingRule rule3 = sheetCF.createConditionalFormattingRule(\r
                 ComparisonOperator.NOT_EQUAL, "15");\r
-        assertEquals(ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS, rule3.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS.id, rule3.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS, rule3.getConditionTypeType());\r
         assertEquals("15", rule3.getFormula1());\r
         assertEquals(ComparisonOperator.NOT_EQUAL, rule3.getComparisonOperation());\r
 \r
         ConditionalFormattingRule rule4 = sheetCF.createConditionalFormattingRule(\r
                 ComparisonOperator.GT, "0");\r
-        assertEquals(ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS, rule4.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS.id, rule4.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS, rule4.getConditionTypeType());\r
         assertEquals("0", rule4.getFormula1());\r
         assertEquals(ComparisonOperator.GT, rule4.getComparisonOperation());\r
 \r
         ConditionalFormattingRule rule5 = sheetCF.createConditionalFormattingRule(\r
                 ComparisonOperator.LT, "0");\r
-        assertEquals(ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS, rule5.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS.id, rule5.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS, rule5.getConditionTypeType());\r
         assertEquals("0", rule5.getFormula1());\r
         assertEquals(ComparisonOperator.LT, rule5.getComparisonOperation());\r
 \r
         ConditionalFormattingRule rule6 = sheetCF.createConditionalFormattingRule(\r
                 ComparisonOperator.GE, "0");\r
-        assertEquals(ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS, rule6.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS.id, rule6.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS, rule6.getConditionTypeType());\r
         assertEquals("0", rule6.getFormula1());\r
         assertEquals(ComparisonOperator.GE, rule6.getComparisonOperation());\r
 \r
         ConditionalFormattingRule rule7 = sheetCF.createConditionalFormattingRule(\r
                 ComparisonOperator.LE, "0");\r
-        assertEquals(ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS, rule7.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS.id, rule7.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS, rule7.getConditionTypeType());\r
         assertEquals("0", rule7.getFormula1());\r
         assertEquals(ComparisonOperator.LE, rule7.getComparisonOperation());\r
 \r
         ConditionalFormattingRule rule8 = sheetCF.createConditionalFormattingRule(\r
                 ComparisonOperator.BETWEEN, "0", "5");\r
-        assertEquals(ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS, rule8.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS.id, rule8.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS, rule8.getConditionTypeType());\r
         assertEquals("0", rule8.getFormula1());\r
         assertEquals("5", rule8.getFormula2());\r
         assertEquals(ComparisonOperator.BETWEEN, rule8.getComparisonOperation());\r
 \r
         ConditionalFormattingRule rule9 = sheetCF.createConditionalFormattingRule(\r
                 ComparisonOperator.NOT_BETWEEN, "0", "5");\r
-        assertEquals(ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS, rule9.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS.id, rule9.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS, rule9.getConditionTypeType());\r
         assertEquals("0", rule9.getFormula1());\r
         assertEquals("5", rule9.getFormula2());\r
         assertEquals(ComparisonOperator.NOT_BETWEEN, rule9.getComparisonOperation());\r
@@ -456,7 +466,7 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
 \r
         // CF1 has two rules: values less than -3 are bold-italic red, values greater than 3 are green\r
         ConditionalFormattingRule rule1 = cf1.getRule(0);\r
-        assertEquals(ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS, rule1.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS, rule1.getConditionTypeType());\r
         assertEquals(ComparisonOperator.GT, rule1.getComparisonOperation());\r
         assertEquals("3", rule1.getFormula1());\r
         assertNull(rule1.getFormula2());\r
@@ -470,7 +480,7 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
         assertFalse(fmt1.isItalic());\r
 \r
         ConditionalFormattingRule rule2 = cf1.getRule(1);\r
-        assertEquals(ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS, rule2.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS, rule2.getConditionTypeType());\r
         assertEquals(ComparisonOperator.LT, rule2.getComparisonOperation());\r
         assertEquals("-3", rule2.getFormula1());\r
         assertNull(rule2.getFormula2());\r
@@ -490,7 +500,7 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
         assertEquals("B9", regions2[0].formatAsString());\r
 \r
         ConditionalFormattingRule rule3 = cf2.getRule(0);\r
-        assertEquals(ConditionalFormattingRule.CONDITION_TYPE_FORMULA, rule3.getConditionType());\r
+        assertEquals(ConditionType.FORMULA, rule3.getConditionTypeType());\r
         assertEquals(ComparisonOperator.NO_COMPARISON, rule3.getComparisonOperation());\r
         assertEquals("$A$8>5", rule3.getFormula1());\r
         assertNull(rule3.getFormula2());\r
@@ -514,13 +524,13 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
         assertEquals(2, cf3.getNumberOfRules());\r
 \r
         ConditionalFormattingRule rule4 = cf3.getRule(0);\r
-        assertEquals(ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS, rule4.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS, rule4.getConditionTypeType());\r
         assertEquals(ComparisonOperator.LE, rule4.getComparisonOperation());\r
         assertEquals("\"AAA\"", rule4.getFormula1());\r
         assertNull(rule4.getFormula2());\r
 \r
         ConditionalFormattingRule rule5 = cf3.getRule(1);\r
-        assertEquals(ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS, rule5.getConditionType());\r
+        assertEquals(ConditionType.CELL_VALUE_IS, rule5.getConditionTypeType());\r
         assertEquals(ComparisonOperator.BETWEEN, rule5.getComparisonOperation());\r
         assertEquals("\"A\"", rule5.getFormula1());\r
         assertEquals("\"AAA\"", rule5.getFormula2());\r
@@ -576,6 +586,7 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
         \r
         assertEquals(1, cf.getNumberOfRules());\r
         cr = cf.getRule(0);\r
+        assertEquals(ConditionType.CELL_VALUE_IS, cr.getConditionTypeType());\r
         // TODO Check the rest of this\r
         \r
         // Highlight 10-30 - Column D\r