changeset 6530:c8f3fda9ec22

RT-24614: in equals method, if both values are strings, compare them with String equalsIgnoreCase
author David Grieve<david.grieve@oracle.com>
date Thu, 20 Mar 2014 18:57:39 -0400
parents 901931021129
children e07207914384
files modules/graphics/src/main/java/com/sun/javafx/css/ParsedValueImpl.java modules/graphics/src/test/java/com/sun/javafx/css/ParsedValueTest.java
diffstat 2 files changed, 136 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/javafx/css/ParsedValueImpl.java	Thu Mar 20 15:43:04 2014 -0400
+++ b/modules/graphics/src/main/java/com/sun/javafx/css/ParsedValueImpl.java	Thu Mar 20 18:57:39 2014 -0400
@@ -364,10 +364,11 @@
 
         } else {
 
-            if (other.value instanceof ParsedValueImpl[][]
-                    || other.value instanceof ParsedValueImpl[]) return false;
+            // RT-24614 - "CENTER" should equal "center"
+            if (this.value instanceof String && other.value instanceof String) {
+                return this.value.toString().equalsIgnoreCase(other.value.toString());
+            }
 
-            // we know other is not null because of the instanceof check
             return (this.value != null
                     ? this.value.equals(other.value)
                     : other.value == null);
--- a/modules/graphics/src/test/java/com/sun/javafx/css/ParsedValueTest.java	Thu Mar 20 15:43:04 2014 -0400
+++ b/modules/graphics/src/test/java/com/sun/javafx/css/ParsedValueTest.java	Thu Mar 20 18:57:39 2014 -0400
@@ -28,6 +28,9 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+
+import com.sun.javafx.css.converters.StringConverter;
+import com.sun.javafx.css.parser.CSSParser;
 import javafx.scene.text.Font;
 
 import org.junit.Test;
@@ -260,6 +263,135 @@
 
 
     }
+
+    @Test
+    public void test_RT_24614() {
+
+        ParsedValue<String,String> value1 =
+                new ParsedValueImpl<>("FOO", null);
+
+        ParsedValue<String,String> value2 =
+                new ParsedValueImpl<>("FOO", null);
+
+        assertTrue(value1.equals(value2));
+
+        value1 =
+                new ParsedValueImpl<>("FOO", null);
+
+        value2 =
+                new ParsedValueImpl<>("foo", null);
+
+        assertTrue(value1.equals(value2));
+
+        ParsedValueImpl<ParsedValue<?,Size>,Number> value3 =
+                new ParsedValueImpl<>(
+                        new ParsedValueImpl<Size,Size>(new Size(1.0, SizeUnits.PX), null),
+                        SizeConverter.getInstance());
+
+        value1 =
+                new ParsedValueImpl<>("FOO", null);
+
+        assertFalse(value1.equals(value3));
+        assertFalse(value3.equals(value1));
+
+        ParsedValue<ParsedValue[],String[]> value4 =
+                new ParsedValueImpl<>(
+                        new ParsedValueImpl[] {
+                                new ParsedValueImpl<String,String>("FOO", null),
+                                new ParsedValueImpl<String,String>("BAR", null)
+                        }, null
+                );
+
+        ParsedValue<ParsedValue[],String[]> value5 =
+                new ParsedValueImpl<>(
+                        new ParsedValueImpl[] {
+                                new ParsedValueImpl<String,String>("foo", null),
+                                new ParsedValueImpl<String,String>("bar", null)
+                        }, null
+                );
+        assertTrue(value4.equals(value5));
+        assertTrue(value5.equals(value4));
+
+        value4 =
+                new ParsedValueImpl<>(
+                        new ParsedValueImpl[] {
+                                new ParsedValueImpl<String,String>("FOO", null),
+                                new ParsedValueImpl<String,String>("BAR", null)
+                        }, null
+                );
+
+        value5 =
+                new ParsedValueImpl<>(
+                        new ParsedValueImpl[] {
+                                new ParsedValueImpl<String,String>("foo", null),
+                                new ParsedValueImpl<String,String>("foo", null)
+                        }, null
+                );
+        assertFalse(value4.equals(value5));
+        assertFalse(value5.equals(value4));
+
+        ParsedValue<ParsedValue[][],String[][]> value6 =
+                new ParsedValueImpl<>(
+                        new ParsedValueImpl[][] {
+                                new ParsedValueImpl[] {
+                                        new ParsedValueImpl<String,String>("foo", null),
+                                        new ParsedValueImpl<String,String>("bar", null)
+                                },
+                                new ParsedValueImpl[] {
+                                        new ParsedValueImpl<String,String>("FOO", null),
+                                        new ParsedValueImpl<String,String>("BAR", null)
+                                }
+                        }, null
+                );
+
+        ParsedValue<ParsedValue[][],String[][]> value7 =
+                new ParsedValueImpl<>(
+                        new ParsedValueImpl[][] {
+                                new ParsedValueImpl[] {
+                                        new ParsedValueImpl<String,String>("FOO", null),
+                                        new ParsedValueImpl<String,String>("BAR", null)
+                                },
+                                new ParsedValueImpl[] {
+                                        new ParsedValueImpl<String,String>("foo", null),
+                                        new ParsedValueImpl<String,String>("bar", null)
+                                }
+                        }, null
+                );
+
+        assertTrue(value6.equals(value7));
+        assertTrue(value7.equals(value6));
+
+        value6 =
+                new ParsedValueImpl<>(
+                        new ParsedValueImpl[][] {
+                                new ParsedValueImpl[] {
+                                        new ParsedValueImpl<String,String>("foo", null),
+                                        new ParsedValueImpl<String,String>("bar", null)
+                                },
+                                new ParsedValueImpl[] {
+                                        new ParsedValueImpl<String,String>("FOO", null),
+                                        new ParsedValueImpl<String,String>("BAR", null)
+                                }
+                        }, null
+                );
+
+        value7 =
+                new ParsedValueImpl<>(
+                        new ParsedValueImpl[][] {
+                                new ParsedValueImpl[] {
+                                        new ParsedValueImpl<String,String>("FOO", null),
+                                        new ParsedValueImpl<String,String>("BAR", null)
+                                },
+                                new ParsedValueImpl[] {
+                                        new ParsedValueImpl<String,String>("foo", null),
+                                        new ParsedValueImpl<String,String>("foo", null)
+                                }
+                        }, null
+                );
+
+        assertFalse(value6.equals(value7));
+        assertFalse(value7.equals(value6));
+    }
     
     private void writeBinary(ParsedValueImpl parsedValue) {