From 22c2e794d6cc37718d7783bbee0de18ba8393d94 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sun, 19 Jul 2015 02:35:04 +0000 Subject: [PATCH] #58130 Fix the icon formatting read/write CF test git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691788 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/hssf/record/cf/Threshold.java | 11 +++++++++++ .../ss/usermodel/BaseTestConditionalFormatting.java | 7 +++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/cf/Threshold.java b/src/java/org/apache/poi/hssf/record/cf/Threshold.java index 462027807..414bf0f4c 100644 --- a/src/java/org/apache/poi/hssf/record/cf/Threshold.java +++ b/src/java/org/apache/poi/hssf/record/cf/Threshold.java @@ -73,6 +73,14 @@ public final class Threshold { } public void setType(byte type) { this.type = type; + + // Ensure the value presense / absense is consistent for the new type + if (type == RangeType.MIN.id || type == RangeType.MAX.id || + type == RangeType.FORMULA.id) { + this.value = null; + } else if (value == null) { + this.value = 0d; + } } public void setType(int type) { this.type = (byte)type; @@ -86,6 +94,9 @@ public final class Threshold { } public void setParsedExpression(Ptg[] ptgs) { formula = Formula.create(ptgs); + if (ptgs.length > 0) { + this.value = null; + } } public Double getValue() { diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java index 1204355fa..602c33495 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java @@ -555,11 +555,11 @@ public abstract class BaseTestConditionalFormatting extends TestCase { assertEquals("Values", s.getRow(0).getCell(0).toString()); assertEquals("10.0", s.getRow(2).getCell(0).toString()); - // Check we found all the conditional formattings rules we should have + // Check we found all the conditional formatting rules we should have SheetConditionalFormatting sheetCF = s.getSheetConditionalFormatting(); int numCF = 3; int numCF12 = 15; - int numCFEX = 0; // TODO This should be 1, but we don't support CFEX formattings yet + int numCFEX = 0; // TODO This should be 2, but we don't support CFEX formattings yet assertEquals(numCF+numCF12+numCFEX, sheetCF.getNumConditionalFormattings()); int fCF = 0, fCF12 = 0, fCFEX = 0; @@ -982,8 +982,7 @@ public abstract class BaseTestConditionalFormatting extends TestCase { assertEquals(BorderFormatting.BORDER_HAIR, r1fp.getBorderRight()); } - // TODO Fix this test to work for HSSF - public void DISABLEDtestCreateIconFormatting() { + public void testCreateIconFormatting() { Workbook workbook = _testDataProvider.createWorkbook(); Sheet sheet = workbook.createSheet();