aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2015-07-14 21:45:23 +0000
committerNick Burch <nick@apache.org>2015-07-14 21:45:23 +0000
commit1596a62368ca2a84e6f33853232e9fd1d598e13b (patch)
treef3cd17de92675adfc0863e9b16e3f1b41ecfcb49 /src
parentb2d6118eeb179296655e872e1ec0ccfdbe7d48d3 (diff)
downloadpoi-1596a62368ca2a84e6f33853232e9fd1d598e13b.tar.gz
poi-1596a62368ca2a84e6f33853232e9fd1d598e13b.zip
Start checking the CF colours in the unit tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691092 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java5
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFConditionalFormatting.java11
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java7
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java10
4 files changed, 27 insertions, 6 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java
index d2dc28dda7..19fd5a5b48 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java
@@ -170,10 +170,7 @@ public class XSSFColor implements Color {
return null;
}
for(byte c : rgb) {
- int i = (int)c;
- if(i < 0) {
- i += 256;
- }
+ int i = c & 0xff;
String cs = Integer.toHexString(i);
if(cs.length() == 1) {
sb.append('0');
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFConditionalFormatting.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFConditionalFormatting.java
index c6823c9721..81220355d8 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFConditionalFormatting.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFConditionalFormatting.java
@@ -19,6 +19,7 @@
package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.BaseTestConditionalFormatting;
+import org.apache.poi.ss.usermodel.Color;
import org.apache.poi.xssf.XSSFITestDataProvider;
/**
@@ -29,6 +30,16 @@ public class TestXSSFConditionalFormatting extends BaseTestConditionalFormatting
super(XSSFITestDataProvider.instance);
}
+ protected void assertColour(String hexExpected, Color actual) {
+ assertNotNull("Colour must be given", actual);
+ XSSFColor colour = (XSSFColor)actual;
+ if (hexExpected.length() == 8) {
+ assertEquals(hexExpected, colour.getARGBHex());
+ } else {
+ assertEquals(hexExpected, colour.getARGBHex().substring(2));
+ }
+ }
+
public void testRead(){
testRead("WithConditionalFormatting.xlsx");
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
index 69c61a701a..697f350c7e 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
@@ -22,7 +22,9 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.hssf.HSSFITestDataProvider;
+import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.BaseTestConditionalFormatting;
+import org.apache.poi.ss.usermodel.Color;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.SheetConditionalFormatting;
import org.apache.poi.ss.usermodel.Workbook;
@@ -34,6 +36,11 @@ public final class TestHSSFConditionalFormatting extends BaseTestConditionalForm
public TestHSSFConditionalFormatting(){
super(HSSFITestDataProvider.instance);
}
+ protected void assertColour(String hexExpected, Color actual) {
+ assertNotNull("Colour must be given", actual);
+ HSSFColor colour = (HSSFColor)actual;
+ assertEquals(hexExpected, colour.getHexString());
+ }
public void testRead() {
testRead("WithConditionalFormatting.xls");
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
index 6dde39730f..5ee58d4b48 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
@@ -35,6 +35,8 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
public BaseTestConditionalFormatting(ITestDataProvider testDataProvider){
_testDataProvider = testDataProvider;
}
+
+ protected abstract void assertColour(String hexExpected, Color actual);
public void testBasic() {
Workbook wb = _testDataProvider.createWorkbook();
@@ -592,8 +594,12 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
assertEquals(ComparisonOperator.GT, cr.getComparisonOperation());
assertEquals("0", cr.getFormula1());
assertEquals(null, cr.getFormula2());
-// assertColourGreen(cr);
- // TODO Colour checking
+ // TODO Should the colours be slightly different like this?
+ if (cr instanceof HSSFConditionalFormattingRule) {
+ assertColour("CCCC:FFFF:CCCC", cr.getPatternFormatting().getFillBackgroundColorColor());
+ } else {
+ assertColour("C6EFCE", cr.getPatternFormatting().getFillBackgroundColorColor());
+ }
// Highlight 10-30 - Column D