aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2009-11-25 11:45:37 +0000
committerNick Burch <nick@apache.org>2009-11-25 11:45:37 +0000
commit5cf512174e197b200f72656096d9b426aa2be137 (patch)
tree8f23cafd5d2ee3506d38281ec77ca1434e54f7ae /src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java
parentab15ad1b66e1695a6a0c061a6d094f4561ccd966 (diff)
downloadpoi-5cf512174e197b200f72656096d9b426aa2be137.tar.gz
poi-5cf512174e197b200f72656096d9b426aa2be137.zip
Patch from Jeremy Michelson (with slight tweaks) - bug #48274 - fix erronious wrapping of byte colours in HSSFPalette.findSimilarColor
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@884061 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java')
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java57
1 files changed, 56 insertions, 1 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java
index 39050ccd8c..751547071f 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java
@@ -17,6 +17,7 @@
package org.apache.poi.hssf.usermodel;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
@@ -24,6 +25,7 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.PaletteRecord;
+import org.apache.poi.hssf.usermodel.HSSFPalette;
import org.apache.poi.hssf.util.HSSFColor;
/**
@@ -137,6 +139,49 @@ public final class TestHSSFPalette extends TestCase {
public void testFindSimilar() {
HSSFWorkbook book = new HSSFWorkbook();
HSSFPalette p = book.getCustomPalette();
+
+ /* first test the defaults */
+ assertTrue(
+ Arrays.equals(
+ new short[] {(short) 255, (short) 255, (short) 0}, // not [204, 255, 255]
+ p.findSimilarColor((byte) 204, (byte) 255, (byte) 0).getTriplet()
+ )
+ );
+
+ assertTrue(
+ Arrays.equals(
+ new short[] {(short) 153, (short) 204, (short) 0}, // not [128, 0, 0]
+ p.findSimilarColor((byte) 128, (byte) 255, (byte) 0).getTriplet()
+ )
+ );
+
+ assertTrue(
+ Arrays.equals(
+ new short[] {(short) 0, (short) 255, (short) 0}, // not [0, 51, 102]
+ p.findSimilarColor((byte) 0, (byte) 255, (byte) 102).getTriplet()
+ )
+ );
+
+ assertTrue(
+ Arrays.equals(
+ new short[] {(short) 0, (short) 102, (short) 204}, // not [255, 102, 0]
+ p.findSimilarColor((byte) 0, (byte) 102, (byte) 255).getTriplet()
+ )
+ );
+
+ assertTrue(
+ Arrays.equals(
+ new short[] {(short) 255, (short) 0, (short) 255}, // not [128, 0, 0]
+ p.findSimilarColor((byte) 128, (byte) 0, (byte) 255).getTriplet()
+ )
+ );
+
+ assertTrue(
+ Arrays.equals(
+ new short[] {(short) 255, (short) 0, (short) 255}, // not [255, 255, 153]
+ p.findSimilarColor((byte) 255, (byte) 0, (byte) 153).getTriplet()
+ )
+ );
// Add a few edge colours in
@@ -175,8 +220,18 @@ public final class TestHSSFPalette extends TestCase {
p.getColor((short)12).getHexString(),
p.findSimilarColor((byte)-1, (byte)2, (byte)10).getHexString()
);
+
+ // And with ints not bytes
+ assertEquals(
+ p.getColor((short)11).getHexString(),
+ p.findSimilarColor(255, 2, 1).getHexString()
+ );
+ assertEquals(
+ p.getColor((short)12).getHexString(),
+ p.findSimilarColor(255, 2, 10).getHexString()
+ );
}
-
+
/**
* Verifies that the generated gnumeric-format string values match the
* hardcoded values in the HSSFColor default color palette