aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/testcases/org/apache/poi
diff options
context:
space:
mode:
authorGreg Woolsey <gwoolsey@apache.org>2017-05-26 23:14:48 +0000
committerGreg Woolsey <gwoolsey@apache.org>2017-05-26 23:14:48 +0000
commitc844803b660d90b835a1de0dacbd7e369ec30db8 (patch)
tree73f331759737b1e9b2d2a6420ab9ad4ca91810f0 /src/ooxml/testcases/org/apache/poi
parent585d77c9cf0001d61f20cd59317bab7e2c5b9369 (diff)
downloadpoi-c844803b660d90b835a1de0dacbd7e369ec30db8.tar.gz
poi-c844803b660d90b835a1de0dacbd7e369ec30db8.zip
Bug 60898 - XSSFColor's getARGB() method returns a wrong color value when a workbook has a custom indexed color
teach XSSFColor and most things that create instances about indexed colors. Null is a valid value for IndexedColorMap instances - the existing built-in default colors are used. Whenever a workbook style is accessible in the call hierarchy its color mappings are passed down now. Thanks for the unit test in the issue, it now passes. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1796359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/testcases/org/apache/poi')
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java2
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java23
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java2
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java8
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFCellFill.java8
5 files changed, 32 insertions, 11 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
index c907d40db3..7bc283ef5f 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
@@ -73,7 +73,7 @@ public class TestXSSFCellStyle {
assertEquals(1, stylesTable.putBorder(borderB));
ctFill = CTFill.Factory.newInstance();
- XSSFCellFill fill = new XSSFCellFill(ctFill);
+ XSSFCellFill fill = new XSSFCellFill(ctFill, null);
long fillId = stylesTable.putFill(fill);
assertEquals(2, fillId);
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 38406c30a4..64d27548d4 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java
@@ -17,12 +17,16 @@
package org.apache.poi.xssf.usermodel;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.junit.Test;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColors;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRgbColor;
public final class TestXSSFColor {
@@ -180,4 +184,21 @@ public final class TestXSSFColor {
wb.close();
}
+
+ @Test
+ public void testCustomIndexedColour() throws Exception {
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("customIndexedColors.xlsx");
+ XSSFCell cell = wb.getSheetAt(1).getRow(0).getCell(0);
+ XSSFColor color = cell.getCellStyle().getFillForegroundColorColor();
+ CTColors ctColors = wb.getStylesSource().getCTStylesheet().getColors();
+
+ CTRgbColor ctRgbColor = ctColors.getIndexedColors()
+ .getRgbColorList()
+ .get(color.getIndex());
+
+ String hexRgb = ctRgbColor.getDomNode().getAttributes().getNamedItem("rgb").getNodeValue();
+
+ assertEquals(hexRgb, color.getARGBHex());
+
+ }
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java
index 2eeb5e8bb0..58e2f85ff6 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java
@@ -256,7 +256,7 @@ public final class TestXSSFFont extends BaseTestFont{
byte[] bytes = Integer.toHexString(0xF1F1F1).getBytes(LocaleUtil.CHARSET_1252);
color.setRgb(bytes);
- XSSFColor newColor=new XSSFColor(color);
+ XSSFColor newColor=new XSSFColor(color, null);
xssfFont.setColor(newColor);
assertEquals(ctFont.getColorArray(0).getRgb()[2],newColor.getRGB()[2]);
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
index 27bfe5b2a0..25de3892c6 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
@@ -1892,7 +1892,7 @@ public final class TestXSSFSheet extends BaseTestXSheet {
try {
XSSFSheet sh = wb.createSheet();
assertTrue(sh.getCTWorksheet().getSheetPr() == null || !sh.getCTWorksheet().getSheetPr().isSetTabColor());
- sh.setTabColor(new XSSFColor(IndexedColors.RED));
+ sh.setTabColor(new XSSFColor(IndexedColors.RED, null));
assertTrue(sh.getCTWorksheet().getSheetPr().isSetTabColor());
assertEquals(IndexedColors.RED.index,
sh.getCTWorksheet().getSheetPr().getTabColor().getIndexed());
@@ -1908,8 +1908,8 @@ public final class TestXSSFSheet extends BaseTestXSheet {
XSSFSheet sh = wb.createSheet();
assertTrue(sh.getCTWorksheet().getSheetPr() == null || !sh.getCTWorksheet().getSheetPr().isSetTabColor());
assertNull(sh.getTabColor());
- sh.setTabColor(new XSSFColor(IndexedColors.RED));
- XSSFColor expected = new XSSFColor(IndexedColors.RED);
+ sh.setTabColor(new XSSFColor(IndexedColors.RED, null));
+ XSSFColor expected = new XSSFColor(IndexedColors.RED, null);
assertEquals(expected, sh.getTabColor());
} finally {
wb.close();
@@ -1925,7 +1925,7 @@ public final class TestXSSFSheet extends BaseTestXSheet {
assertNull(wb.getSheet("default").getTabColor());
// test indexed-colored sheet
- XSSFColor expected = new XSSFColor(IndexedColors.RED);
+ XSSFColor expected = new XSSFColor(IndexedColors.RED, null);
assertEquals(expected, wb.getSheet("indexedRed").getTabColor());
// test regular-colored (non-indexed, ARGB) sheet
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 832d6bfb2b..c9279e26df 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
@@ -40,7 +40,7 @@ public class TestXSSFCellFill {
@Test
public void testGetFillBackgroundColor() {
CTFill ctFill = CTFill.Factory.newInstance();
- XSSFCellFill cellFill = new XSSFCellFill(ctFill);
+ XSSFCellFill cellFill = new XSSFCellFill(ctFill, null);
CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
CTColor bgColor = ctPatternFill.addNewBgColor();
assertNotNull(cellFill.getFillBackgroundColor());
@@ -51,7 +51,7 @@ public class TestXSSFCellFill {
@Test
public void testGetFillForegroundColor() {
CTFill ctFill = CTFill.Factory.newInstance();
- XSSFCellFill cellFill = new XSSFCellFill(ctFill);
+ XSSFCellFill cellFill = new XSSFCellFill(ctFill, null);
CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
CTColor fgColor = ctPatternFill.addNewFgColor();
assertNotNull(cellFill.getFillForegroundColor());
@@ -62,7 +62,7 @@ public class TestXSSFCellFill {
@Test
public void testGetSetPatternType() {
CTFill ctFill = CTFill.Factory.newInstance();
- XSSFCellFill cellFill = new XSSFCellFill(ctFill);
+ XSSFCellFill cellFill = new XSSFCellFill(ctFill, null);
CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
ctPatternFill.setPatternType(STPatternType.SOLID);
assertEquals(FillPatternType.SOLID_FOREGROUND.ordinal(), cellFill.getPatternType().intValue()-1);
@@ -71,7 +71,7 @@ public class TestXSSFCellFill {
@Test
public void testGetNotModifies() {
CTFill ctFill = CTFill.Factory.newInstance();
- XSSFCellFill cellFill = new XSSFCellFill(ctFill);
+ XSSFCellFill cellFill = new XSSFCellFill(ctFill, null);
CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
ctPatternFill.setPatternType(STPatternType.DARK_DOWN);
assertEquals(8, cellFill.getPatternType().intValue());