Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVeronika Irvine2005-11-10 16:32:47 +0000
committerVeronika Irvine2005-11-10 16:32:47 +0000
commit375593ba6653fa81268e5bfbc6bd7fb0a56adba8 (patch)
tree55e963e9ecc916c31f20f189e8200759683b9c64 /tests
parent2503053f30d7051ae67b1f8960c73f8d3decfc0a (diff)
downloadeclipse.platform.swt-375593ba6653fa81268e5bfbc6bd7fb0a56adba8.tar.gz
eclipse.platform.swt-375593ba6653fa81268e5bfbc6bd7fb0a56adba8.tar.xz
eclipse.platform.swt-375593ba6653fa81268e5bfbc6bd7fb0a56adba8.zip
Adding hue, saturation and brightness tests
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_RGB.java274
1 files changed, 271 insertions, 3 deletions
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_RGB.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_RGB.java
index 96d0ba76f5..ef6d910e40 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_RGB.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_RGB.java
@@ -87,6 +87,147 @@ public void test_ConstructorIII() {
}
+public void test_ConstructorFFF() {
+
+ RGB rgb = new RGB(0f,0f,0f);
+ rgb = new RGB(0f,1f,1f);
+ rgb = new RGB(0f,1f,0f);
+ rgb = new RGB(0f,0f,1f);
+ rgb = new RGB(0f,0.6f,0.4f);
+ rgb = new RGB(1f,0f,1f);
+ rgb = new RGB(1f,1f,1f);
+ rgb = new RGB(1f,0f,1f);
+ rgb = new RGB(1f,1f,0f);
+ rgb = new RGB(1f,0.6f,0.4f);
+ rgb = new RGB(59f,0f,1f);
+ rgb = new RGB(59f,1f,1f);
+ rgb = new RGB(59f,0f,1f);
+ rgb = new RGB(59f,1f,0f);
+ rgb = new RGB(59f,0.6f,0.4f);
+ rgb = new RGB(60f,0f,1f);
+ rgb = new RGB(60f,1f,1f);
+ rgb = new RGB(60f,0f,1f);
+ rgb = new RGB(60f,1f,0f);
+ rgb = new RGB(60f,0.6f,0.4f);
+ rgb = new RGB(61f,0f,1f);
+ rgb = new RGB(61f,1f,1f);
+ rgb = new RGB(61f,0f,1f);
+ rgb = new RGB(61f,1f,0f);
+ rgb = new RGB(61f,0.6f,0.4f);
+ rgb = new RGB(119f,0f,1f);
+ rgb = new RGB(119f,1f,1f);
+ rgb = new RGB(119f,0f,1f);
+ rgb = new RGB(119f,1f,0f);
+ rgb = new RGB(119f,0.6f,0.4f);
+ rgb = new RGB(120f,0f,1f);
+ rgb = new RGB(120f,1f,1f);
+ rgb = new RGB(120f,0f,1f);
+ rgb = new RGB(120f,1f,0f);
+ rgb = new RGB(120f,0.6f,0.4f);
+ rgb = new RGB(121f,0f,1f);
+ rgb = new RGB(121f,1f,1f);
+ rgb = new RGB(121f,0f,1f);
+ rgb = new RGB(121f,1f,0f);
+ rgb = new RGB(121f,0.6f,0.4f);
+ rgb = new RGB(179f,0f,1f);
+ rgb = new RGB(179f,1f,1f);
+ rgb = new RGB(179f,0f,1f);
+ rgb = new RGB(179f,1f,0f);
+ rgb = new RGB(179f,0.6f,0.4f);
+ rgb = new RGB(180f,0f,1f);
+ rgb = new RGB(180f,1f,1f);
+ rgb = new RGB(180f,0f,1f);
+ rgb = new RGB(180f,1f,0f);
+ rgb = new RGB(180f,0.6f,0.4f);
+ rgb = new RGB(181f,0f,1f);
+ rgb = new RGB(181f,1f,1f);
+ rgb = new RGB(181f,0f,1f);
+ rgb = new RGB(181f,1f,0f);
+ rgb = new RGB(181f,0.6f,0.4f);
+ rgb = new RGB(239f,0f,1f);
+ rgb = new RGB(239f,1f,1f);
+ rgb = new RGB(239f,0f,1f);
+ rgb = new RGB(239f,1f,0f);
+ rgb = new RGB(239f,0.6f,0.4f);
+ rgb = new RGB(240f,0f,1f);
+ rgb = new RGB(240f,1f,1f);
+ rgb = new RGB(240f,0f,1f);
+ rgb = new RGB(240f,1f,0f);
+ rgb = new RGB(240f,0.6f,0.4f);
+ rgb = new RGB(241f,0f,1f);
+ rgb = new RGB(241f,1f,1f);
+ rgb = new RGB(241f,0f,1f);
+ rgb = new RGB(241f,1f,0f);
+ rgb = new RGB(241f,0.6f,0.4f);
+ rgb = new RGB(299f,0f,1f);
+ rgb = new RGB(299f,1f,1f);
+ rgb = new RGB(299f,0f,1f);
+ rgb = new RGB(299f,1f,0f);
+ rgb = new RGB(299f,0.6f,0.4f);
+ rgb = new RGB(300f,0f,1f);
+ rgb = new RGB(300f,1f,1f);
+ rgb = new RGB(300f,0f,1f);
+ rgb = new RGB(300f,1f,0f);
+ rgb = new RGB(300f,0.6f,0.4f);
+ rgb = new RGB(301f,0f,1f);
+ rgb = new RGB(301f,1f,1f);
+ rgb = new RGB(301f,0f,1f);
+ rgb = new RGB(301f,1f,0f);
+ rgb = new RGB(301f,0.6f,0.4f);
+ rgb = new RGB(359f,0f,1f);
+ rgb = new RGB(359f,1f,1f);
+ rgb = new RGB(359f,0f,1f);
+ rgb = new RGB(359f,1f,0f);
+ rgb = new RGB(359f,0.6f,0.4f);
+ rgb = new RGB(360f,0f,1f);
+ rgb = new RGB(360f,1f,1f);
+ rgb = new RGB(360f,0f,1f);
+ rgb = new RGB(360f,1f,0f);
+ rgb = new RGB(360f,0.6f,0.4f);
+
+ try {
+ rgb = new RGB(400f, 0.5f, 0.5f);
+ fail("No exception thrown for hue > 360");
+ }
+ catch (IllegalArgumentException e) {
+ }
+
+ try {
+ rgb = new RGB(-5f, 0.5f, 0.5f);
+ fail("No exception thrown for hue < 0");
+ }
+ catch (IllegalArgumentException e) {
+ }
+
+ try {
+ rgb = new RGB(200f, -0.5f, 0.5f);
+ fail("No exception thrown for saturation < 0");
+ }
+ catch (IllegalArgumentException e) {
+ }
+
+ try {
+ rgb = new RGB(200f, 300f, 0.5f);
+ fail("No exception thrown for saturation > 1");
+ }
+ catch (IllegalArgumentException e) {
+ }
+
+ try {
+ rgb = new RGB(200f, 0.5f, -0.5f);
+ fail("No exception thrown for brightness < 0");
+ }
+ catch (IllegalArgumentException e) {
+ }
+
+ try {
+ rgb = new RGB(200f, 0.5f, 400f);
+ fail("No exception thrown for brightness > 1");
+ }
+ catch (IllegalArgumentException e) {
+ }
+}
+
public void test_equalsLjava_lang_Object() {
int r = 0, g = 127, b = 254;
RGB rgb1 = new RGB(r, g, b);
@@ -108,8 +249,133 @@ public void test_equalsLjava_lang_Object() {
rgb1.equals(new RGB(r+1, g+1, b+1))) {
fail("Comparing two RGB instances with different combination of R G B parameters found equal");
}
-}
+ float hue = 220f, sat = 0.6f, bright = 0.7f;
+ rgb1 = new RGB(hue, sat, bright);
+ rgb2 = rgb1;
+ if (!rgb1.equals(rgb2)) {
+ fail("Two references to the same RGB instance not found equal");
+ }
+
+ rgb2 = new RGB(hue, sat, bright);
+ if (!rgb1.equals(rgb2)) {
+ fail("References to two different RGB instances with same H S B parameters not found equal");
+ }
+
+ if (rgb1.equals(new RGB(hue+1, sat, bright)) ||
+ rgb1.equals(new RGB(hue, sat+0.1f, bright)) ||
+ rgb1.equals(new RGB(hue, sat, bright+0.1f)) ||
+ rgb1.equals(new RGB(hue+1, sat+0.1f, bright+0.1f))) {
+ fail("Comparing two RGB instances with different combination of H S B parameters found equal");
+ }
+}
+public void test_getHSB() {
+ float[] hsb = new float[] {
+ 0f,0f,0f,
+ 0f,1f,1f,
+ 0f,1f,0f,
+ 0f,0f,1f,
+ 0f,0.6f,0.4f,
+ 1f,0f,1f,
+ 1f,1f,1f,
+ 1f,0f,1f,
+ 1f,1f,0f,
+ 1f,0.6f,0.4f,
+ 59f,0f,1f,
+ 59f,1f,1f,
+ 59f,0f,1f,
+ 59f,1f,0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
+ 359f,1f,0f,
+ 359f,0.6f,0.4f,
+ 360f,0f,1f,
+ 360f,1f,1f,
+ 360f,0f,1f,
+ 360f,1f,0f,
+ 360f,0.6f,0.4f,
+ 220f,0.6f,0.7f};
+ for (int i = 0; i < hsb.length; i+=3) {
+ RGB rgb1 = new RGB(hsb[i], hsb[i+1], hsb[i+2]);
+ float[] hsb2 = rgb1.getHSB();
+ RGB rgb2 = new RGB(hsb2[0], hsb2[1], hsb2[2]);
+ if (!rgb1.equals(rgb2)) {
+ fail("Two references to the same RGB using getHSB() function not found equal");
+ }
+ }
+}
public void test_hashCode() {
int r = 255, g = 100, b = 0;
RGB rgb1 = new RGB(r, g, b);
@@ -127,7 +393,6 @@ public void test_hashCode() {
fail("Two RGB instances with different R G B parameters returned the same hash code");
}
}
-
public void test_toString() {
RGB rgb = new RGB(0, 100, 200);
@@ -137,7 +402,6 @@ public void test_toString() {
fail("RGB.toString returns a null or empty String");
}
}
-
public static Test suite() {
TestSuite suite = new TestSuite();
java.util.Vector methodNames = methodNames();
@@ -150,14 +414,18 @@ public static Test suite() {
public static java.util.Vector methodNames() {
java.util.Vector methodNames = new java.util.Vector();
methodNames.addElement("test_ConstructorIII");
+ methodNames.addElement("test_ConstructorFFF");
methodNames.addElement("test_equalsLjava_lang_Object");
+ methodNames.addElement("test_getHSB");
methodNames.addElement("test_hashCode");
methodNames.addElement("test_toString");
return methodNames;
}
protected void runTest() throws Throwable {
if (getName().equals("test_ConstructorIII")) test_ConstructorIII();
+ else if (getName().equals("test_ConstructorFFF")) test_ConstructorFFF();
else if (getName().equals("test_equalsLjava_lang_Object")) test_equalsLjava_lang_Object();
+ else if (getName().equals("test_getHSB")) test_getHSB();
else if (getName().equals("test_hashCode")) test_hashCode();
else if (getName().equals("test_toString")) test_toString();
}

Back to the top