aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/testcases/org/apache/poi/xssf/usermodel
diff options
context:
space:
mode:
Diffstat (limited to 'src/ooxml/testcases/org/apache/poi/xssf/usermodel')
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java62
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFCellFill.java73
2 files changed, 71 insertions, 64 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java
index b2aa11447b..6f31cc49f4 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java
@@ -24,49 +24,49 @@ import org.apache.poi.xssf.XSSFTestDataSamples;
public final class TestXSSFColor extends TestCase {
public void testIndexedColour() throws Exception {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48779.xlsx");
-
+
// Check the CTColor is as expected
XSSFColor indexed = wb.getCellStyleAt((short)1).getFillBackgroundXSSFColor();
assertEquals(true, indexed.getCTColor().isSetIndexed());
assertEquals(64, indexed.getCTColor().getIndexed());
assertEquals(false, indexed.getCTColor().isSetRgb());
assertEquals(null, indexed.getCTColor().getRgb());
-
+
// Now check the XSSFColor
// Note - 64 is a special "auto" one with no rgb equiv
assertEquals(64, indexed.getIndexed());
assertEquals(null, indexed.getRgb());
assertEquals(null, indexed.getRgbWithTint());
assertEquals(null, indexed.getARGBHex());
-
+
// Now move to one with indexed rgb values
indexed.setIndexed(59);
assertEquals(true, indexed.getCTColor().isSetIndexed());
assertEquals(59, indexed.getCTColor().getIndexed());
assertEquals(false, indexed.getCTColor().isSetRgb());
assertEquals(null, indexed.getCTColor().getRgb());
-
+
assertEquals(59, indexed.getIndexed());
assertEquals("FF333300", indexed.getARGBHex());
-
+
assertEquals(3, indexed.getRgb().length);
assertEquals(0x33, indexed.getRgb()[0]);
assertEquals(0x33, indexed.getRgb()[1]);
assertEquals(0x00, indexed.getRgb()[2]);
-
+
assertEquals(4, indexed.getARgb().length);
assertEquals(-1, indexed.getARgb()[0]);
assertEquals(0x33, indexed.getARgb()[1]);
assertEquals(0x33, indexed.getARgb()[2]);
assertEquals(0x00, indexed.getARgb()[3]);
-
+
// You don't get tinted indexed colours, sorry...
assertEquals(null, indexed.getRgbWithTint());
}
-
+
public void testRGBColour() throws Exception {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50299.xlsx");
-
+
// Check the CTColor is as expected
XSSFColor rgb3 = wb.getCellStyleAt((short)25).getFillForegroundXSSFColor();
assertEquals(false, rgb3.getCTColor().isSetIndexed());
@@ -75,37 +75,39 @@ public final class TestXSSFColor extends TestCase {
assertEquals(-0.34999, rgb3.getCTColor().getTint(), 0.00001);
assertEquals(true, rgb3.getCTColor().isSetRgb());
assertEquals(3, rgb3.getCTColor().getRgb().length);
-
+
// Now check the XSSFColor
assertEquals(0, rgb3.getIndexed());
assertEquals(-0.34999, rgb3.getTint(), 0.00001);
-
+
assertEquals("FFFFFFFF", rgb3.getARGBHex());
assertEquals(3, rgb3.getRgb().length);
assertEquals(-1, rgb3.getRgb()[0]);
assertEquals(-1, rgb3.getRgb()[1]);
assertEquals(-1, rgb3.getRgb()[2]);
-
+
assertEquals(4, rgb3.getARgb().length);
assertEquals(-1, rgb3.getARgb()[0]);
assertEquals(-1, rgb3.getARgb()[1]);
assertEquals(-1, rgb3.getARgb()[2]);
assertEquals(-1, rgb3.getARgb()[3]);
-
+
// Tint doesn't have the alpha
+ // tint = -0.34999
+ // 255 * (1 + tint) = 165 truncated
+ // or (byte) -91 (which is 165 - 256)
assertEquals(3, rgb3.getRgbWithTint().length);
- assertEquals(0, rgb3.getRgbWithTint()[0]);
- assertEquals(0, rgb3.getRgbWithTint()[1]);
- assertEquals(0, rgb3.getRgbWithTint()[2]);
-
- // Set the colour to black, will get translated internally
- // (Excel stores 3 colour white and black wrong!)
- rgb3.setRgb(new byte[] {-1,-1,-1});
- assertEquals("FFFFFFFF", rgb3.getARGBHex());
+ assertEquals(-91, rgb3.getRgbWithTint()[0]);
+ assertEquals(-91, rgb3.getRgbWithTint()[1]);
+ assertEquals(-91, rgb3.getRgbWithTint()[2]);
+
+ // Set the color to black (no theme).
+ rgb3.setRgb(new byte[] {0, 0, 0});
+ assertEquals("FF000000", rgb3.getARGBHex());
assertEquals(0, rgb3.getCTColor().getRgb()[0]);
assertEquals(0, rgb3.getCTColor().getRgb()[1]);
assertEquals(0, rgb3.getCTColor().getRgb()[2]);
-
+
// Set another, is fine
rgb3.setRgb(new byte[] {16,17,18});
assertEquals("FF101112", rgb3.getARGBHex());
@@ -113,45 +115,45 @@ public final class TestXSSFColor extends TestCase {
assertEquals(0x11, rgb3.getCTColor().getRgb()[1]);
assertEquals(0x12, rgb3.getCTColor().getRgb()[2]);
}
-
+
public void testARGBColour() throws Exception {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48779.xlsx");
-
+
// Check the CTColor is as expected
XSSFColor rgb4 = wb.getCellStyleAt((short)1).getFillForegroundXSSFColor();
assertEquals(false, rgb4.getCTColor().isSetIndexed());
assertEquals(0, rgb4.getCTColor().getIndexed());
assertEquals(true, rgb4.getCTColor().isSetRgb());
assertEquals(4, rgb4.getCTColor().getRgb().length);
-
+
// Now check the XSSFColor
assertEquals(0, rgb4.getIndexed());
assertEquals(0.0, rgb4.getTint());
-
+
assertEquals("FFFF0000", rgb4.getARGBHex());
assertEquals(3, rgb4.getRgb().length);
assertEquals(-1, rgb4.getRgb()[0]);
assertEquals(0, rgb4.getRgb()[1]);
assertEquals(0, rgb4.getRgb()[2]);
-
+
assertEquals(4, rgb4.getARgb().length);
assertEquals(-1, rgb4.getARgb()[0]);
assertEquals(-1, rgb4.getARgb()[1]);
assertEquals(0, rgb4.getARgb()[2]);
assertEquals(0, rgb4.getARgb()[3]);
-
+
// Tint doesn't have the alpha
assertEquals(3, rgb4.getRgbWithTint().length);
assertEquals(-1, rgb4.getRgbWithTint()[0]);
assertEquals(0, rgb4.getRgbWithTint()[1]);
assertEquals(0, rgb4.getRgbWithTint()[2]);
-
+
// Turn on tinting, and check it behaves
// TODO These values are suspected to be wrong...
rgb4.setTint(0.4);
assertEquals(0.4, rgb4.getTint());
-
+
assertEquals(3, rgb4.getRgbWithTint().length);
assertEquals(-1, rgb4.getRgbWithTint()[0]);
assertEquals(102, rgb4.getRgbWithTint()[1]);
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFCellFill.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFCellFill.java
index 2ad4f5645d..b268410bfa 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFCellFill.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFCellFill.java
@@ -31,34 +31,34 @@ import junit.framework.TestCase;
public class TestXSSFCellFill extends TestCase {
-
- public void testGetFillBackgroundColor() {
- CTFill ctFill = CTFill.Factory.newInstance();
- XSSFCellFill cellFill = new XSSFCellFill(ctFill);
- CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
- CTColor bgColor = ctPatternFill.addNewBgColor();
- assertNotNull(cellFill.getFillBackgroundColor());
- bgColor.setIndexed(2);
- assertEquals(2, cellFill.getFillBackgroundColor().getIndexed());
- }
-
- public void testGetFillForegroundColor() {
- CTFill ctFill = CTFill.Factory.newInstance();
- XSSFCellFill cellFill = new XSSFCellFill(ctFill);
- CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
- CTColor fgColor = ctPatternFill.addNewFgColor();
- assertNotNull(cellFill.getFillForegroundColor());
- fgColor.setIndexed(8);
- assertEquals(8, cellFill.getFillForegroundColor().getIndexed());
- }
-
- public void testGetSetPatternType() {
- CTFill ctFill = CTFill.Factory.newInstance();
- XSSFCellFill cellFill = new XSSFCellFill(ctFill);
- CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
- ctPatternFill.setPatternType(STPatternType.SOLID);
- //assertEquals(FillPatternType.SOLID_FOREGROUND.ordinal(), cellFill.getPatternType().ordinal());
- }
+
+ public void testGetFillBackgroundColor() {
+ CTFill ctFill = CTFill.Factory.newInstance();
+ XSSFCellFill cellFill = new XSSFCellFill(ctFill);
+ CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
+ CTColor bgColor = ctPatternFill.addNewBgColor();
+ assertNotNull(cellFill.getFillBackgroundColor());
+ bgColor.setIndexed(2);
+ assertEquals(2, cellFill.getFillBackgroundColor().getIndexed());
+ }
+
+ public void testGetFillForegroundColor() {
+ CTFill ctFill = CTFill.Factory.newInstance();
+ XSSFCellFill cellFill = new XSSFCellFill(ctFill);
+ CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
+ CTColor fgColor = ctPatternFill.addNewFgColor();
+ assertNotNull(cellFill.getFillForegroundColor());
+ fgColor.setIndexed(8);
+ assertEquals(8, cellFill.getFillForegroundColor().getIndexed());
+ }
+
+ public void testGetSetPatternType() {
+ CTFill ctFill = CTFill.Factory.newInstance();
+ XSSFCellFill cellFill = new XSSFCellFill(ctFill);
+ CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
+ ctPatternFill.setPatternType(STPatternType.SOLID);
+ //assertEquals(FillPatternType.SOLID_FOREGROUND.ordinal(), cellFill.getPatternType().ordinal());
+ }
public void testGetNotModifies() {
CTFill ctFill = CTFill.Factory.newInstance();
@@ -75,11 +75,16 @@ public class TestXSSFCellFill extends TestCase {
XSSFColor foregroundColor = cellWithThemeColor.getCellStyle().getFillForegroundXSSFColor();
byte[] rgb = foregroundColor.getRgb();
byte[] rgbWithTint = foregroundColor.getRgbWithTint();
- assertEquals(rgb[0],-18);
- assertEquals(rgb[1],-20);
- assertEquals(rgb[2],-31);
- assertEquals(rgbWithTint[0],-12);
- assertEquals(rgbWithTint[1],-13);
- assertEquals(rgbWithTint[2],-20);
+ // Dk2
+ assertEquals(rgb[0],31);
+ assertEquals(rgb[1],73);
+ assertEquals(rgb[2],125);
+ // Dk2, lighter 40% (tint is about 0.39998)
+ // 31 * (1.0 - 0.39998) + (255 - 255 * (1.0 - 0.39998)) = 120.59552 => 120 (byte)
+ // 73 * (1.0 - 0.39998) + (255 - 255 * (1.0 - 0.39998)) = 145.79636 => -111 (byte)
+ // 125 * (1.0 - 0.39998) + (255 - 255 * (1.0 - 0.39998)) = 176.99740 => -80 (byte)
+ assertEquals(rgbWithTint[0],120);
+ assertEquals(rgbWithTint[1],-111);
+ assertEquals(rgbWithTint[2],-80);
}
}