]> source.dussan.org Git - poi.git/commitdiff
#58130 Stub the CF Color Scale unit tests
authorNick Burch <nick@apache.org>
Sun, 19 Jul 2015 02:54:25 +0000 (02:54 +0000)
committerNick Burch <nick@apache.org>
Sun, 19 Jul 2015 02:54:25 +0000 (02:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691789 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java

index 602c334958b09368beffeeff0a8663e8184022ec..1a130b7510e3afc068f0f6de98789c5239bcb327 100644 (file)
@@ -559,7 +559,7 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
         SheetConditionalFormatting sheetCF = s.getSheetConditionalFormatting();\r
         int numCF = 3;\r
         int numCF12 = 15;\r
-        int numCFEX = 0; // TODO This should be 2, but we don't support CFEX formattings yet\r
+        int numCFEX = 0; // TODO This should be 2, but we don't support CFEX formattings yet, see #58149\r
         assertEquals(numCF+numCF12+numCFEX, sheetCF.getNumConditionalFormattings());\r
         \r
         int fCF = 0, fCF12 = 0, fCFEX = 0;\r
@@ -648,26 +648,18 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
         // TODO Support Data Bars, then check the rest of this rule\r
         \r
         \r
-        // Colours R->G - Column F\r
+        // Colours Red->Yellow->Green - Column F\r
         cf = sheetCF.getConditionalFormattingAt(3);\r
         assertEquals(1, cf.getFormattingRanges().length);\r
         assertEquals("F2:F17", cf.getFormattingRanges()[0].formatAsString());\r
-        \r
-        assertEquals(1, cf.getNumberOfRules());\r
-        cr = cf.getRule(0);\r
-        assertEquals(ConditionType.COLOR_SCALE, cr.getConditionTypeType());\r
-        // TODO Support Color Scales, then check the rest of this rule\r
+        assertColorScale(cf, "F8696B", "FFEB84", "63BE7B");\r
 \r
         \r
-        // Colours BWR - Column G\r
+        // Colours Blue->White->Red - Column G\r
         cf = sheetCF.getConditionalFormattingAt(4);\r
         assertEquals(1, cf.getFormattingRanges().length);\r
         assertEquals("G2:G17", cf.getFormattingRanges()[0].formatAsString());\r
-        \r
-        assertEquals(1, cf.getNumberOfRules());\r
-        cr = cf.getRule(0);\r
-        assertEquals(ConditionType.COLOR_SCALE, cr.getConditionTypeType());\r
-        // TODO Support Color Scales, then check the rest of this rule\r
+        assertColorScale(cf, "5A8AC6", "FCFCFF", "F8696B");\r
 \r
         \r
         // Icons : Default - Column H, percentage thresholds\r
@@ -808,6 +800,50 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
             assertEquals(null, th.getFormula());\r
         }\r
     }\r
+    \r
+    private void assertColorScale(ConditionalFormatting cf, String... colors) {\r
+        assertEquals(1, cf.getNumberOfRules());\r
+        ConditionalFormattingRule cr = cf.getRule(0);\r
+        assertColorScale(cr, colors);\r
+    }        \r
+    private void assertColorScale(ConditionalFormattingRule cr, String... colors) {\r
+        assertEquals(ConditionType.COLOR_SCALE, cr.getConditionTypeType());\r
+        assertEquals(ComparisonOperator.NO_COMPARISON, cr.getComparisonOperation());\r
+        assertEquals(null, cr.getFormula1());\r
+        assertEquals(null, cr.getFormula2());\r
+        \r
+        // TODO Implement\r
+/*\r
+        ColorScaleFormatting color = cr.getColorScaleFormatting();\r
+        assertNotNull(color);\r
+        assertNotNull(color.getColors());\r
+        assertNotNull(color.getThresholds());\r
+        assertEquals(colors.length, color.getNumControlPoints());\r
+        assertEquals(colors.length, color.getColors().length);\r
+        assertEquals(colors.length, color.getThresholds().length);\r
+        \r
+        // Thresholds should be Min / (evenly spaced) / Max\r
+        int steps = 100 / (colors.length-1);\r
+        for (int i=0; i<colors.length; i++) {\r
+            ConditionalFormattingThreshold th = color.getThresholds()[i];\r
+            if (i == 0) {\r
+                assertEquals(RangeType.MIN, th.getRangeType());\r
+            } else if (i == colors.length-1) {\r
+                assertEquals(RangeType.MAX, th.getRangeType());\r
+            } else {\r
+                assertEquals(RangeType.PERCENT, th.getRangeType());\r
+                assertEquals(steps*i, th.getValue());\r
+            }\r
+            assertEquals(null, th.getFormula());\r
+        }\r
+        \r
+        // Colors should match\r
+        for (int i=0; i<colors.length; i++) {\r
+            Color c = color.getColors()[i];\r
+            assertEquals(colors[i], c.toString());\r
+        }\r
+*/\r
+    }\r
 \r
     public void testCreateFontFormatting() {\r
         Workbook workbook = _testDataProvider.createWorkbook();\r