harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r427121 [26/29] - in /incubator/harmony/enhanced/classlib/trunk/modules/swing: make/ src/main/java/common/javax/swing/ src/main/java/common/javax/swing/text/ src/main/java/common/javax/swing/text/html/ src/main/java/common/javax/swing/text/...
Date Mon, 31 Jul 2006 14:08:55 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_TextDecorationTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_TextDecorationTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_TextDecorationTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_TextDecorationTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,555 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Alexey A. Ivanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import java.util.Enumeration;
+
+import javax.swing.BasicSwingTestCase;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.html.CSS.Attribute;
+
+public class StyleSheet_ConvertAttr_TextDecorationTest extends BasicSwingTestCase {
+    private StyleSheet ss;
+    private AttributeSet empty;
+    private AttributeSet attr;
+    private MutableAttributeSet simple;
+    private Object cssValue;
+    private Object scValue;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        ss = new StyleSheet();
+        empty = ss.getEmptySet();
+        simple = new SimpleAttributeSet();
+    }
+
+    public void testUnderline() {
+        attr = ss.addAttribute(empty, StyleConstants.Underline,
+                               Boolean.TRUE);
+
+        Enumeration names = attr.getAttributeNames();
+        Object name = names.nextElement();
+        assertSame(Attribute.TEXT_DECORATION, name);
+        assertFalse(names.hasMoreElements());
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        scValue = attr.getAttribute(StyleConstants.Underline);
+        assertSame(Boolean.class, scValue.getClass());
+        assertNotSame(Boolean.class, cssValue.getClass());
+        assertNotSame(String.class, cssValue.getClass());
+        assertEquals("underline", cssValue.toString());
+        assertTrue(((Boolean)scValue).booleanValue());
+    }
+
+    public void testUnderlineFalse() {
+        attr = ss.addAttribute(empty, StyleConstants.Underline,
+                               Boolean.FALSE);
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        scValue = attr.getAttribute(StyleConstants.Underline);
+        assertEquals(isHarmony() ? "none" : "", cssValue.toString());
+        assertFalse(((Boolean)scValue).booleanValue());
+    }
+
+    public void testStrikeThrough() {
+        attr = ss.addAttribute(empty, StyleConstants.StrikeThrough,
+                               Boolean.TRUE);
+
+        Enumeration names = attr.getAttributeNames();
+        Object name = names.nextElement();
+        assertSame(Attribute.TEXT_DECORATION, name);
+        assertFalse(names.hasMoreElements());
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        scValue = attr.getAttribute(StyleConstants.StrikeThrough);
+        assertSame(Boolean.class, scValue.getClass());
+        assertNotSame(Boolean.class, cssValue.getClass());
+        assertNotSame(String.class, cssValue.getClass());
+        assertEquals("line-through", cssValue.toString());
+        assertTrue(((Boolean)scValue).booleanValue());
+    }
+
+    public void testStrikeThroughFalse() {
+        attr = ss.addAttribute(empty, StyleConstants.StrikeThrough,
+                               Boolean.FALSE);
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        scValue = attr.getAttribute(StyleConstants.StrikeThrough);
+        assertEquals(isHarmony() ? "none" : "", cssValue.toString());
+        assertFalse(((Boolean)scValue).booleanValue());
+    }
+
+    public void testTextDecorationNone() throws Exception {
+        ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION, "none");
+        attr = ss.createSmallAttributeSet(simple);
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("none", cssValue.toString());
+
+        scValue = attr.getAttribute(StyleConstants.Underline);
+        assertFalse(((Boolean)scValue).booleanValue());
+
+        scValue = attr.getAttribute(StyleConstants.StrikeThrough);
+        assertFalse(((Boolean)scValue).booleanValue());
+    }
+
+    public void testTextDecorationUnderline() throws Exception {
+        ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION, "underline");
+        attr = ss.createSmallAttributeSet(simple);
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("underline", cssValue.toString());
+
+        scValue = attr.getAttribute(StyleConstants.Underline);
+        assertTrue(((Boolean)scValue).booleanValue());
+
+        scValue = attr.getAttribute(StyleConstants.StrikeThrough);
+        assertFalse(((Boolean)scValue).booleanValue());
+    }
+
+    public void testTextDecorationLineThrough() throws Exception {
+        ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION, "line-through");
+        attr = ss.createSmallAttributeSet(simple);
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("line-through", cssValue.toString());
+
+        scValue = attr.getAttribute(StyleConstants.Underline);
+        assertFalse(((Boolean)scValue).booleanValue());
+
+        scValue = attr.getAttribute(StyleConstants.StrikeThrough);
+        assertTrue(((Boolean)scValue).booleanValue());
+    }
+
+    public void testTextDecorationUnderlineLineThrough() throws Exception {
+        ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION,
+                           "underline line-through");
+        attr = ss.createSmallAttributeSet(simple);
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("underline line-through", cssValue.toString());
+
+        scValue = attr.getAttribute(StyleConstants.Underline);
+        assertTrue(((Boolean)scValue).booleanValue());
+
+        scValue = attr.getAttribute(StyleConstants.StrikeThrough);
+        assertTrue(((Boolean)scValue).booleanValue());
+    }
+
+    public void testTextDecorationUnderlineThenLineThrough() throws Exception {
+        ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION, "underline");
+        assertEquals(1, simple.getAttributeCount());
+        ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION, "line-through");
+        assertEquals(1, simple.getAttributeCount());
+
+        cssValue = simple.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("line-through", cssValue.toString());
+    }
+
+    public void testTextDecorationUnderlineLineThroughSC() throws Exception {
+        attr = ss.addAttribute(empty, StyleConstants.Underline, Boolean.TRUE);
+        assertEquals(1, attr.getAttributeCount());
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("underline", cssValue.toString());
+        scValue = attr.getAttribute(StyleConstants.Underline);
+        assertTrue(((Boolean)scValue).booleanValue());
+        scValue = attr.getAttribute(StyleConstants.StrikeThrough);
+        assertFalse(((Boolean)scValue).booleanValue());
+
+        attr = ss.addAttribute(attr, StyleConstants.StrikeThrough,
+                               Boolean.TRUE);
+        assertEquals(1, attr.getAttributeCount());
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        if (isHarmony()) {
+            assertEquals("underline line-through", cssValue.toString());
+            scValue = attr.getAttribute(StyleConstants.Underline);
+            assertTrue(((Boolean)scValue).booleanValue());
+            scValue = attr.getAttribute(StyleConstants.StrikeThrough);
+            assertTrue(((Boolean)scValue).booleanValue());
+        } else {
+            assertEquals("line-through", cssValue.toString());
+            scValue = attr.getAttribute(StyleConstants.Underline);
+            assertFalse(((Boolean)scValue).booleanValue());
+            scValue = attr.getAttribute(StyleConstants.StrikeThrough);
+            assertTrue(((Boolean)scValue).booleanValue());
+        }
+    }
+
+    public void testTextDecorationStrikeThrough() throws Exception {
+        ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION, "strike-through");
+        if (isHarmony()) {
+            assertEquals(0, simple.getAttributeCount());
+            return;
+        }
+
+        attr = ss.createSmallAttributeSet(simple);
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("strike-through", cssValue.toString());
+
+        scValue = attr.getAttribute(StyleConstants.Underline);
+        assertFalse(((Boolean)scValue).booleanValue());
+
+        scValue = attr.getAttribute(StyleConstants.StrikeThrough);
+        assertFalse(((Boolean)scValue).booleanValue());
+    }
+
+    public void testTextDecorationOverline() throws Exception {
+        ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION, "overline");
+        attr = ss.createSmallAttributeSet(simple);
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("overline", cssValue.toString());
+
+        scValue = attr.getAttribute(StyleConstants.Underline);
+        assertFalse(((Boolean)scValue).booleanValue());
+
+        scValue = attr.getAttribute(StyleConstants.StrikeThrough);
+        assertFalse(((Boolean)scValue).booleanValue());
+    }
+
+    public void testTextDecorationBlink() throws Exception {
+        ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION, "blink");
+        attr = ss.createSmallAttributeSet(simple);
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("blink", cssValue.toString());
+
+        scValue = attr.getAttribute(StyleConstants.Underline);
+        assertFalse(((Boolean)scValue).booleanValue());
+
+        scValue = attr.getAttribute(StyleConstants.StrikeThrough);
+        assertFalse(((Boolean)scValue).booleanValue());
+    }
+
+    public void testAddAttributesUnderline() throws Exception {
+        simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
+        attr = ss.addAttributes(empty, simple);
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("underline", cssValue.toString());
+
+        scValue = attr.getAttribute(StyleConstants.Underline);
+        assertTrue(((Boolean)scValue).booleanValue());
+
+        scValue = attr.getAttribute(StyleConstants.StrikeThrough);
+        assertFalse(((Boolean)scValue).booleanValue());
+    }
+
+    public void testAddAttributesStrikeThrough() throws Exception {
+        simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
+        attr = ss.addAttributes(empty, simple);
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("line-through", cssValue.toString());
+
+        scValue = attr.getAttribute(StyleConstants.Underline);
+        assertFalse(((Boolean)scValue).booleanValue());
+
+        scValue = attr.getAttribute(StyleConstants.StrikeThrough);
+        assertTrue(((Boolean)scValue).booleanValue());
+    }
+
+    public void testAddAttributesUnderlineStrikeThrough() throws Exception {
+        attr = ss.addAttribute(empty, StyleConstants.Underline, Boolean.TRUE);
+        simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
+        attr = ss.addAttributes(attr, simple);
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        if (isHarmony()) {
+            assertEquals("underline line-through", cssValue.toString());
+            scValue = attr.getAttribute(StyleConstants.Underline);
+            assertTrue(((Boolean)scValue).booleanValue());
+            scValue = attr.getAttribute(StyleConstants.StrikeThrough);
+            assertTrue(((Boolean)scValue).booleanValue());
+        } else {
+            assertTrue("underline".equals(cssValue.toString())
+                       ^ "line-through".equals(cssValue.toString()));
+        }
+    }
+
+    public void testAddAttributesStrikeThroughUnderline() throws Exception {
+        simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
+        simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
+        assertEquals(2, simple.getAttributeCount());
+
+        attr = ss.addAttributes(empty, simple);
+        assertEquals(1, attr.getAttributeCount());
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        if (isHarmony()) {
+            assertEquals("underline line-through", cssValue.toString());
+            scValue = attr.getAttribute(StyleConstants.Underline);
+            assertTrue(((Boolean)scValue).booleanValue());
+            scValue = attr.getAttribute(StyleConstants.StrikeThrough);
+            assertTrue(((Boolean)scValue).booleanValue());
+        } else {
+            assertTrue("underline".equals(cssValue.toString())
+                       ^ "line-through".equals(cssValue.toString()));
+        }
+    }
+
+    public void testIsDefinedUnderline() throws Exception {
+        attr = ss.addAttribute(empty, StyleConstants.Underline, Boolean.TRUE);
+
+        assertTrue(attr.isDefined(Attribute.TEXT_DECORATION));
+        assertTrue(attr.isDefined(StyleConstants.Underline));
+        assertTrue(attr.isDefined(StyleConstants.StrikeThrough));
+    }
+
+    public void testIsDefinedStrikeThrough() throws Exception {
+        attr = ss.addAttribute(empty, StyleConstants.StrikeThrough,
+                               Boolean.TRUE);
+
+        assertTrue(attr.isDefined(Attribute.TEXT_DECORATION));
+        assertTrue(attr.isDefined(StyleConstants.Underline));
+        assertTrue(attr.isDefined(StyleConstants.StrikeThrough));
+    }
+
+    public void testContainsAttributeUnderline() throws Exception {
+        attr = ss.addAttribute(empty, StyleConstants.Underline, Boolean.TRUE);
+
+        assertTrue(attr.containsAttribute(StyleConstants.Underline,
+                                          Boolean.TRUE));
+        assertFalse(attr.containsAttribute(StyleConstants.Underline,
+                                           Boolean.FALSE));
+        assertFalse(attr.containsAttribute(StyleConstants.StrikeThrough,
+                                           Boolean.TRUE));
+        assertTrue(attr.containsAttribute(StyleConstants.StrikeThrough,
+                                          Boolean.FALSE));
+    }
+
+    public void testContainsAttributeStrikeThrough() throws Exception {
+        attr = ss.addAttribute(empty, StyleConstants.StrikeThrough,
+                               Boolean.TRUE);
+
+        assertFalse(attr.containsAttribute(StyleConstants.Underline,
+                                           Boolean.TRUE));
+        assertTrue(attr.containsAttribute(StyleConstants.Underline,
+                                          Boolean.FALSE));
+        assertTrue(attr.containsAttribute(StyleConstants.StrikeThrough,
+                                          Boolean.TRUE));
+        assertFalse(attr.containsAttribute(StyleConstants.StrikeThrough,
+                                           Boolean.FALSE));
+    }
+
+    public void testContainsAttributeUnderlineStrikeThrough() throws Exception {
+        if (!isHarmony()) {
+            return;
+        }
+
+        attr = ss.addAttribute(empty, StyleConstants.Underline, Boolean.TRUE);
+        attr = ss.addAttribute(attr, StyleConstants.StrikeThrough,
+                               Boolean.TRUE);
+
+        assertTrue(attr.containsAttribute(StyleConstants.Underline,
+                                          Boolean.TRUE));
+        assertFalse(attr.containsAttribute(StyleConstants.Underline,
+                                           Boolean.FALSE));
+        assertTrue(attr.containsAttribute(StyleConstants.StrikeThrough,
+                                          Boolean.TRUE));
+        assertFalse(attr.containsAttribute(StyleConstants.StrikeThrough,
+                                           Boolean.FALSE));
+    }
+
+    public void testContainsAttributesUnderline() throws Exception {
+        simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
+        attr = ss.addAttributes(empty, simple);
+        assertTrue(attr.containsAttributes(simple));
+
+        simple.removeAttribute(StyleConstants.Underline);
+        simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
+        assertFalse(attr.containsAttributes(simple));
+    }
+
+    public void testContainsAttributesUnderlineFalse() throws Exception {
+        attr = ss.addAttribute(empty, StyleConstants.Underline, Boolean.TRUE);
+        assertTrue(attr.containsAttributes(simple));
+
+        simple.addAttribute(StyleConstants.StrikeThrough, Boolean.FALSE);
+        assertTrue(attr.containsAttributes(simple));
+    }
+
+    public void testContainsAttributesStrikeThrough() throws Exception {
+        simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
+        attr = ss.addAttributes(empty, simple);
+        assertTrue(attr.containsAttributes(simple));
+
+        simple.removeAttribute(StyleConstants.StrikeThrough);
+        simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
+        assertFalse(attr.containsAttributes(simple));
+    }
+
+    public void testContainsAttributesStrikeThroughFalse() throws Exception {
+        attr = ss.addAttribute(empty, StyleConstants.StrikeThrough,
+                               Boolean.TRUE);
+
+        simple.addAttribute(StyleConstants.Underline, Boolean.FALSE);
+        assertTrue(attr.containsAttributes(simple));
+    }
+
+    public void testContainsAttributesUnderlineStrikeThrough()
+        throws Exception {
+
+        if (!isHarmony()) {
+            return;
+        }
+
+        simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
+        simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
+        attr = ss.addAttributes(empty, simple);
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("underline line-through", cssValue.toString());
+
+        assertTrue(attr.containsAttributes(simple));
+
+        simple.removeAttribute(StyleConstants.StrikeThrough);
+        assertTrue(attr.containsAttributes(simple));
+    }
+
+    public void testRemoveAttributeUnderline() throws Exception {
+        attr = ss.addAttribute(empty, StyleConstants.Underline, Boolean.TRUE);
+        assertEquals(1, attr.getAttributeCount());
+
+        attr = ss.removeAttribute(attr, StyleConstants.StrikeThrough);
+        if (isHarmony()) {
+            assertEquals(1, attr.getAttributeCount());
+        } else {
+            assertEquals(0, attr.getAttributeCount());
+            return;
+        }
+
+        attr = ss.removeAttribute(attr, StyleConstants.Underline);
+        assertEquals(0, attr.getAttributeCount());
+    }
+
+    public void testRemoveAttributeStrikeThrough() throws Exception {
+        attr = ss.addAttribute(empty, StyleConstants.StrikeThrough,
+                               Boolean.TRUE);
+
+
+        attr = ss.removeAttribute(attr, StyleConstants.Underline);
+        if (isHarmony()) {
+            assertEquals(1, attr.getAttributeCount());
+        } else {
+            assertEquals(0, attr.getAttributeCount());
+            return;
+        }
+
+        attr = ss.removeAttribute(attr, StyleConstants.StrikeThrough);
+        assertEquals(0, attr.getAttributeCount());
+    }
+
+    public void testRemoveAttributesUnderline() throws Exception {
+        simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
+        attr = ss.addAttributes(empty, simple);
+        assertTrue(attr.containsAttributes(simple));
+
+        attr = ss.removeAttributes(attr, simple);
+        if (isHarmony()) {
+            assertEquals(0, attr.getAttributeCount());
+        } else {
+            assertEquals(1, attr.getAttributeCount());
+            cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+            assertEquals("underline", cssValue.toString());
+        }
+    }
+
+    public void testRemoveAttributesStrikeThrough() throws Exception {
+        simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
+        attr = ss.addAttributes(empty, simple);
+        assertTrue(attr.containsAttributes(simple));
+
+        attr = ss.removeAttributes(attr, simple);
+        if (isHarmony()) {
+            assertEquals(0, attr.getAttributeCount());
+        } else {
+            assertEquals(1, attr.getAttributeCount());
+            cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+            assertEquals("line-through", cssValue.toString());
+        }
+    }
+
+    public void testRemoveAttributesUnderlineStrikeThrough01()
+        throws Exception {
+
+        if (!isHarmony()) {
+            return;
+        }
+
+        simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
+        simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
+        attr = ss.addAttributes(empty, simple);
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("underline line-through", cssValue.toString());
+
+        assertTrue(attr.containsAttributes(simple));
+
+        attr = ss.removeAttributes(attr, simple);
+        assertEquals(0, attr.getAttributeCount());
+    }
+
+    public void testRemoveAttributesUnderlineStrikeThrough02()
+        throws Exception {
+
+        if (!isHarmony()) {
+            return;
+        }
+
+        simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
+        simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
+        attr = ss.addAttributes(empty, simple);
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("underline line-through", cssValue.toString());
+
+        simple.removeAttribute(StyleConstants.Underline);
+        attr = ss.removeAttributes(attr, simple);
+        assertEquals(1, attr.getAttributeCount());
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("underline", cssValue.toString());
+    }
+
+    public void testRemoveAttributesUnderlineStrikeThrough03()
+        throws Exception {
+
+        if (!isHarmony()) {
+            return;
+        }
+
+        simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
+        simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
+        attr = ss.addAttributes(empty, simple);
+
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("underline line-through", cssValue.toString());
+
+        simple.removeAttribute(StyleConstants.StrikeThrough);
+        attr = ss.removeAttributes(attr, simple);
+        assertEquals(1, attr.getAttributeCount());
+        cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
+        assertEquals("line-through", cssValue.toString());
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_TextIndentTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_TextIndentTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_TextIndentTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_TextIndentTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,44 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Alexey A. Ivanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import javax.swing.text.StyleConstants;
+
+public class StyleSheet_ConvertAttr_TextIndentTest
+    extends StyleSheet_ConvertAttr_MarginTestCase {
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        scKey = StyleConstants.FirstLineIndent;
+        cssKey = CSS.Attribute.TEXT_INDENT;
+    }
+
+    // Overrides the super class test-case with same name.
+    // The last assertion is modified (that's the only difference)
+    public void testLengthMinus11_1pt() {
+        ss.addCSSAttribute(simple, cssKey, "-11.1pt");
+        attr = ss.createSmallAttributeSet(simple);
+
+        cssValue = attr.getAttribute(cssKey);
+        scValue = attr.getAttribute(scKey);
+        assertEquals("-11.1pt", cssValue.toString());
+        assertEquals(-11.1f, ((Float)scValue).floatValue(), 0f);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_TextTransformTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_TextTransformTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_TextTransformTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_TextTransformTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,86 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Alexey A. Ivanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import javax.swing.BasicSwingTestCase;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.html.CSS.Attribute;
+
+import junit.framework.TestCase;
+
+public class StyleSheet_ConvertAttr_TextTransformTest extends TestCase {
+    private StyleSheet ss;
+    private MutableAttributeSet simple;
+    private Object cssValue;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        ss = new StyleSheet();
+        simple = new SimpleAttributeSet();
+    }
+
+    public void testTextTransformNone() throws Exception {
+        ss.addCSSAttribute(simple, Attribute.TEXT_TRANSFORM, "none");
+        cssValue = simple.getAttribute(Attribute.TEXT_TRANSFORM);
+        assertEquals("none", cssValue.toString());
+    }
+
+    public void testTextTransformCapitalize() throws Exception {
+        ss.addCSSAttribute(simple, Attribute.TEXT_TRANSFORM, "capitalize");
+        cssValue = simple.getAttribute(Attribute.TEXT_TRANSFORM);
+        assertEquals("capitalize", cssValue.toString());
+    }
+
+    public void testTextTransformUppercase() throws Exception {
+        ss.addCSSAttribute(simple, Attribute.TEXT_TRANSFORM, "uppercase");
+        cssValue = simple.getAttribute(Attribute.TEXT_TRANSFORM);
+        assertEquals("uppercase", cssValue.toString());
+    }
+
+    public void testTextTransformLowercase() throws Exception {
+        ss.addCSSAttribute(simple, Attribute.TEXT_TRANSFORM, "lowercase");
+        cssValue = simple.getAttribute(Attribute.TEXT_TRANSFORM);
+        assertEquals("lowercase", cssValue.toString());
+    }
+
+    public void testTextTransformUpperCase() throws Exception {
+        // Invalid value
+        ss.addCSSAttribute(simple, Attribute.TEXT_TRANSFORM, "upper-case");
+        cssValue = simple.getAttribute(Attribute.TEXT_TRANSFORM);
+        if (BasicSwingTestCase.isHarmony()) {
+            assertEquals(0, simple.getAttributeCount());
+            assertNull(cssValue);
+        } else {
+            assertEquals("upper-case", cssValue.toString());
+        }
+    }
+
+    public void testTextTransformLowerCase() throws Exception {
+        ss.addCSSAttribute(simple, Attribute.TEXT_TRANSFORM, "lower-case");
+        cssValue = simple.getAttribute(Attribute.TEXT_TRANSFORM);
+        if (BasicSwingTestCase.isHarmony()) {
+            assertEquals(0, simple.getAttributeCount());
+            assertNull(cssValue);
+        } else {
+            assertEquals("lower-case", cssValue.toString());
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_VerticalAlignTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_VerticalAlignTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_VerticalAlignTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_VerticalAlignTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,100 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Alexey A. Ivanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import javax.swing.BasicSwingTestCase;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.html.CSS.Attribute;
+
+import junit.framework.TestCase;
+
+public class StyleSheet_ConvertAttr_VerticalAlignTest extends TestCase {
+    private StyleSheet ss;
+    private MutableAttributeSet simple;
+    private Object cssValue;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        ss = new StyleSheet();
+        simple = new SimpleAttributeSet();
+    }
+
+    public void testVerticalAlignBaseline() {
+        ss.addCSSAttribute(simple, Attribute.VERTICAL_ALIGN, "baseline");
+        cssValue = simple.getAttribute(Attribute.VERTICAL_ALIGN);
+        assertEquals("baseline", cssValue.toString());
+    }
+
+    public void testVerticalAlignMiddle() {
+        ss.addCSSAttribute(simple, Attribute.VERTICAL_ALIGN, "middle");
+        cssValue = simple.getAttribute(Attribute.VERTICAL_ALIGN);
+        assertEquals("middle", cssValue.toString());
+    }
+
+    public void testVerticalAlignSub() {
+        ss.addCSSAttribute(simple, Attribute.VERTICAL_ALIGN, "sub");
+        cssValue = simple.getAttribute(Attribute.VERTICAL_ALIGN);
+        assertEquals("sub", cssValue.toString());
+    }
+
+    public void testVerticalAlignSuper() {
+        ss.addCSSAttribute(simple, Attribute.VERTICAL_ALIGN, "super");
+        cssValue = simple.getAttribute(Attribute.VERTICAL_ALIGN);
+        assertEquals("super", cssValue.toString());
+    }
+
+    public void testVerticalAlignTextTop() {
+        ss.addCSSAttribute(simple, Attribute.VERTICAL_ALIGN, "text-top");
+        cssValue = simple.getAttribute(Attribute.VERTICAL_ALIGN);
+        assertEquals("text-top", cssValue.toString());
+    }
+
+    public void testVerticalAlignTextBottom() {
+        ss.addCSSAttribute(simple, Attribute.VERTICAL_ALIGN, "text-bottom");
+        cssValue = simple.getAttribute(Attribute.VERTICAL_ALIGN);
+        assertEquals("text-bottom", cssValue.toString());
+    }
+
+    public void testVerticalAlignTop() {
+        ss.addCSSAttribute(simple, Attribute.VERTICAL_ALIGN, "top");
+        cssValue = simple.getAttribute(Attribute.VERTICAL_ALIGN);
+        assertEquals("top", cssValue.toString());
+    }
+
+    public void testVerticalAlignBottom() {
+        ss.addCSSAttribute(simple, Attribute.VERTICAL_ALIGN, "bottom");
+        cssValue = simple.getAttribute(Attribute.VERTICAL_ALIGN);
+        assertEquals("bottom", cssValue.toString());
+    }
+
+
+    public void testVerticalAlignInvalid() {
+        ss.addCSSAttribute(simple, Attribute.VERTICAL_ALIGN, "botom");
+        cssValue = simple.getAttribute(Attribute.VERTICAL_ALIGN);
+        if (BasicSwingTestCase.isHarmony()) {
+            assertEquals(0, simple.getAttributeCount());
+            assertNull(cssValue);
+        } else {
+            assertEquals(1, simple.getAttributeCount());
+            assertEquals("botom", cssValue.toString());
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_WhiteSpaceTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_WhiteSpaceTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_WhiteSpaceTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_WhiteSpaceTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,69 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Alexey A. Ivanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import javax.swing.BasicSwingTestCase;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.html.CSS.Attribute;
+
+import junit.framework.TestCase;
+
+public class StyleSheet_ConvertAttr_WhiteSpaceTest extends TestCase {
+    private StyleSheet ss;
+    private MutableAttributeSet simple;
+    private Object cssValue;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        ss = new StyleSheet();
+        simple = new SimpleAttributeSet();
+    }
+
+    public void testWhiteSpaceNormal() {
+        ss.addCSSAttribute(simple, Attribute.WHITE_SPACE, "normal");
+        cssValue = simple.getAttribute(Attribute.WHITE_SPACE);
+        assertEquals("normal", cssValue.toString());
+    }
+
+    public void testWhiteSpacePre() {
+        ss.addCSSAttribute(simple, Attribute.WHITE_SPACE, "pre");
+        cssValue = simple.getAttribute(Attribute.WHITE_SPACE);
+        assertEquals("pre", cssValue.toString());
+    }
+
+    public void testWhiteSpaceNowrap() {
+        ss.addCSSAttribute(simple, Attribute.WHITE_SPACE, "nowrap");
+        cssValue = simple.getAttribute(Attribute.WHITE_SPACE);
+        assertEquals("nowrap", cssValue.toString());
+    }
+
+    public void testWhiteSpaceInvalid() {
+        ss.addCSSAttribute(simple, Attribute.WHITE_SPACE, "no-wrap");
+        cssValue = simple.getAttribute(Attribute.WHITE_SPACE);
+        if (BasicSwingTestCase.isHarmony()) {
+            assertEquals(0, simple.getAttributeCount());
+            assertNull(cssValue);
+        } else {
+            assertEquals(1, simple.getAttributeCount());
+            assertEquals("no-wrap", cssValue.toString());
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_WidthTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_WidthTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_WidthTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_WidthTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,78 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Alexey A. Ivanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import javax.swing.BasicSwingTestCase;
+
+public class StyleSheet_ConvertAttr_WidthTest
+    extends StyleSheet_ConvertAttr_LengthTestCase {
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        cssKey = CSS.Attribute.WIDTH;
+        negativeValuesInvalid = true;
+    }
+
+    public void testAuto() {
+        ss.addCSSAttribute(simple, cssKey, "auto");
+        cssValue = simple.getAttribute(cssKey);
+        if (BasicSwingTestCase.isHarmony()) {
+            assertEquals(1, simple.getAttributeCount());
+            assertEquals("auto", cssValue.toString());
+        } else {
+            assertEquals(0, simple.getAttributeCount());
+            assertNull(cssValue);
+        }
+    }
+
+    public void testLength0_75em() {
+        ss.addCSSAttribute(simple, cssKey, "0.75em");
+        cssValue = simple.getAttribute(cssKey);
+        if (BasicSwingTestCase.isHarmony()) {
+            assertEquals(1, simple.getAttributeCount());
+            assertEquals("0.75em", cssValue.toString());
+        } else {
+            assertEquals(0, simple.getAttributeCount());
+            assertNull(cssValue);
+        }
+    }
+
+    public void testLength1_25ex() {
+        ss.addCSSAttribute(simple, cssKey, "1.25ex");
+        cssValue = simple.getAttribute(cssKey);
+        if (BasicSwingTestCase.isHarmony()) {
+            assertEquals(1, simple.getAttributeCount());
+            assertEquals("1.25ex", cssValue.toString());
+        } else {
+            assertEquals(0, simple.getAttributeCount());
+            assertNull(cssValue);
+        }
+    }
+
+    public void testLengthMinus11_1Percent() {
+        negativeValuesInvalid = BasicSwingTestCase.isHarmony();
+        super.testLengthMinus11_1Percent();
+    }
+
+    public void testLengthMinus11_1pt() {
+        negativeValuesInvalid = BasicSwingTestCase.isHarmony();
+        super.testLengthMinus11_1pt();
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_WordSpacingTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_WordSpacingTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_WordSpacingTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_WordSpacingTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,29 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Alexey A. Ivanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+public class StyleSheet_ConvertAttr_WordSpacingTest
+    extends StyleSheet_ConvertAttr_SpacingTestCase {
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        cssKey = CSS.Attribute.WORD_SPACING;
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_Large_Test.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_Large_Test.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_Large_Test.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_Large_Test.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,295 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Alexey A. Ivanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import java.util.Enumeration;
+
+import javax.swing.BasicSwingTestCase;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.html.CSS.Attribute;
+
+/**
+ * Tests <code>MutableAttributeSet</code> returned by
+ * <code>StyleSheet.addAttribute</code> method. The returned attribute set
+ * contains <code>CSS.Attribute</code>. It converts the value to
+ * <code>StyleConstants</code> when a <code>StyleConstants</code> attribute
+ * is requested.
+ * <p>
+ * The attribute used for testing is <code>StyleConstants.Italic</code>.
+ * It corresponds to <code>Attribute.FONT_STYLE</code>.
+ *
+ * @see StyleSheet
+ * @see StyleSheet#addAttribute(Object, Object)
+ * @see StyleSheet#createLargeAttributeSet(AttributeSet)
+ * @see CSS.Attribute
+ * @see javax.swing.text.StyleContext.SmallAttributeSet
+ */
+public class StyleSheet_Large_Test extends BasicSwingTestCase {
+    private static final Object scAttribute  = StyleConstants.Italic;
+    private static final Object scValue      = Boolean.TRUE;
+    private static final Object cssAttribute = Attribute.FONT_STYLE;
+
+    private StyleSheet ss;
+    private AttributeSet empty;
+    private AttributeSet attr;
+    private MutableAttributeSet mutable;
+    private int count;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        ss = new StyleSheet();
+        empty = ss.getEmptySet();
+        attr = empty;
+
+        int no = 0;
+        while (!(attr instanceof MutableAttributeSet)) {
+            String number = String.valueOf(no++);
+            attr = ss.addAttribute(attr, "key" + number, "value" + number);
+        }
+        attr = ss.addAttribute(attr, scAttribute, scValue);
+        assertTrue(attr instanceof MutableAttributeSet);
+        count = no + 1;
+
+        mutable = (MutableAttributeSet)attr;
+    }
+
+    public void testGetAttribute() throws Exception {
+        Object value = attr.getAttribute(cssAttribute);
+        assertNotSame(Boolean.class, value.getClass());
+        assertNotSame(String.class, value.getClass());
+        assertEquals("italic", value.toString());
+
+        value = attr.getAttribute(scAttribute);
+        assertSame(Boolean.class, value.getClass());
+        assertTrue(((Boolean)value).booleanValue());
+        assertSame(scValue, value);
+    }
+
+    public void testIsDefined() throws Exception {
+        assertTrue(attr.isDefined(scAttribute));
+        assertTrue(attr.isDefined(cssAttribute));
+    }
+
+    public void testGetNames() throws Exception {
+        final Enumeration keys = attr.getAttributeNames();
+        int stringKeyCount = 0;
+        int nonStringKeyCount = 0;
+        while (keys.hasMoreElements()) {
+            Object key = keys.nextElement();
+            if (key instanceof String) {
+                stringKeyCount++;
+            } else {
+                nonStringKeyCount++;
+                assertSame(cssAttribute, key);
+            }
+        }
+
+        assertEquals(count - 1, stringKeyCount);
+        assertEquals(1, nonStringKeyCount);
+    }
+
+    public void testGetAttributeCount() throws Exception {
+        assertEquals(count, attr.getAttributeCount());
+    }
+
+    public void testIsEqualSame() throws Exception {
+        assertTrue(attr.isEqual(attr));
+
+        final MutableAttributeSet simple = new SimpleAttributeSet(attr);
+        assertTrue(attr.isEqual(simple));
+        assertTrue(simple.isEqual(attr));
+    }
+
+    public void testIsEqualAnother() throws Exception {
+        final MutableAttributeSet simple = new SimpleAttributeSet();
+        fillAttributeSet(simple);
+
+        if (isHarmony()) {
+            assertTrue(simple.isEqual(attr));
+            assertFalse(attr.isEqual(simple));
+        } else {
+            assertFalse(simple.isEqual(attr));
+            assertTrue(attr.isEqual(simple));
+        }
+    }
+
+    public void testCopyAttributes() throws Exception {
+        final AttributeSet copy = attr.copyAttributes();
+        assertNotSame(attr, copy);
+        assertTrue(attr.isEqual(copy));
+        assertTrue(copy.isEqual(attr));
+        assertTrue(copy instanceof MutableAttributeSet);
+    }
+
+    public void testContainsAttribute() throws Exception {
+        assertTrue(attr.containsAttribute(cssAttribute,
+                                          attr.getAttribute(cssAttribute)));
+        assertTrue(attr.containsAttribute(scAttribute, scValue));
+    }
+
+    public void testContainsAttributeAnother() throws Exception {
+        final AttributeSet another = ss.addAttribute(empty,
+                                                     scAttribute, scValue);
+
+        assertEquals(attr.getAttribute(cssAttribute).toString(),
+                     another.getAttribute(cssAttribute).toString());
+        if (isHarmony()) {
+            assertTrue(attr.containsAttribute(cssAttribute,
+                                           another.getAttribute(cssAttribute)));
+        } else {
+            assertFalse(attr.containsAttribute(cssAttribute,
+                                           another.getAttribute(cssAttribute)));
+        }
+    }
+
+    public void testContainsAttributesSame() throws Exception {
+        assertTrue(attr.containsAttributes(attr));
+
+        final MutableAttributeSet simple = new SimpleAttributeSet(attr);
+
+        assertTrue(attr.containsAttributes(simple));
+        assertTrue(simple.containsAttributes(attr));
+    }
+
+    public void testContainsAttributesMutable() throws Exception {
+        final MutableAttributeSet simple = new SimpleAttributeSet();
+        simple.addAttribute(scAttribute, scValue);
+
+        assertTrue(attr.containsAttributes(simple));
+        assertFalse(simple.containsAttributes(attr));
+    }
+
+    public void testContainsAttributesSmall() throws Exception {
+        final AttributeSet another = ss.addAttribute(empty,
+                                                     scAttribute, scValue);
+
+        if (isHarmony()) {
+            assertSame(attr.getAttribute(Attribute.FONT_STYLE),
+                       another.getAttribute(Attribute.FONT_STYLE));
+            assertTrue(attr.containsAttributes(another));
+            assertFalse(another.containsAttributes(attr));
+        } else {
+            assertNotSame(attr.getAttribute(Attribute.FONT_STYLE),
+                          another.getAttribute(Attribute.FONT_STYLE));
+            assertFalse(attr.containsAttributes(another));
+            assertFalse(another.containsAttributes(attr));
+        }
+    }
+
+    public void testAddAttribute() throws Exception {
+        mutable.addAttribute(StyleConstants.Bold, Boolean.TRUE);
+        assertEquals(count + 1, mutable.getAttributeCount());
+        assertItalicButNotBold();
+    }
+
+    public void testAddAttributes() throws Exception {
+        MutableAttributeSet simple = new SimpleAttributeSet();
+        simple.addAttribute(StyleConstants.Bold, Boolean.TRUE);
+
+        mutable.addAttributes(simple);
+        assertEquals(count + 1, mutable.getAttributeCount());
+        assertItalicButNotBold();
+    }
+
+    public void testRemoveAttribute() throws Exception {
+        mutable.removeAttribute(scAttribute);
+        assertEquals(count, mutable.getAttributeCount()); // Didn't change
+
+        mutable.removeAttribute(cssAttribute);
+        assertEquals(count - 1, mutable.getAttributeCount());
+    }
+
+    public void testRemoveAttributesEnumeration() throws Exception {
+        mutable.removeAttributes(new Enumeration() {
+            private int returnedCount = 0;
+
+            public boolean hasMoreElements() {
+                return returnedCount == 0;
+            }
+
+            public Object nextElement() {
+                return returnedCount++ == 0 ? scAttribute : null;
+            }
+        });
+        assertEquals(count, mutable.getAttributeCount()); // Didn't change
+
+        mutable.removeAttributes(new Enumeration() {
+            private int returnedCount = 0;
+
+            public boolean hasMoreElements() {
+                return returnedCount == 0;
+            }
+
+            public Object nextElement() {
+                return returnedCount++ == 0 ? cssAttribute : null;
+            }
+        });
+        assertEquals(count - 1, mutable.getAttributeCount());
+    }
+
+    public void testRemoveAttributesAttributeSet() throws Exception {
+        final MutableAttributeSet sc = new SimpleAttributeSet();
+        sc.addAttribute(scAttribute, scValue);
+
+        mutable.removeAttributes(sc);
+        assertEquals(count, mutable.getAttributeCount()); // Didn't change
+
+        final MutableAttributeSet css = new SimpleAttributeSet();
+        css.addAttribute(cssAttribute, mutable.getAttribute(cssAttribute));
+        mutable.removeAttributes(css);
+        assertEquals(count - 1, mutable.getAttributeCount());
+    }
+
+    private void fillAttributeSet(final MutableAttributeSet simple) {
+        for (int i = 0; i < count - 1; i++) {
+            simple.addAttribute("key" + i, "value" + i);
+        }
+        simple.addAttribute(scAttribute, scValue);
+    }
+
+    private void assertItalicButNotBold() {
+        final Enumeration keys = attr.getAttributeNames();
+        int stringKeyCount = 0;
+        int nonStringKeyCount = 0;
+        boolean cssItalic = false;
+        boolean cssBold = false;
+        boolean scBold = false;
+        while (keys.hasMoreElements()) {
+            Object key = keys.nextElement();
+            if (key instanceof String) {
+                stringKeyCount++;
+            } else {
+                nonStringKeyCount++;
+                cssItalic |= cssAttribute == key;
+                cssBold |= Attribute.FONT_WEIGHT == key;
+                scBold |= StyleConstants.Bold == key;
+            }
+        }
+
+        assertEquals(count - 1, stringKeyCount);
+        assertEquals(2, nonStringKeyCount);
+        assertTrue(cssItalic);
+        assertFalse(cssBold);       // No convertion is performed when used
+        assertTrue(scBold);         // as mutable set
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ResolvedRulesClassTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ResolvedRulesClassTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ResolvedRulesClassTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ResolvedRulesClassTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,164 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Alexey A. Ivanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import java.io.StringReader;
+
+import javax.swing.BasicSwingTestCase;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.Element;
+import javax.swing.text.Style;
+import javax.swing.text.html.HTML.Tag;
+
+public class StyleSheet_ResolvedRulesClassTest extends BasicSwingTestCase {
+    private HTMLDocument doc;
+    private StyleSheet ss;
+    private Style rule;
+    private Element p;
+    private HTMLEditorKit kit;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        setIgnoreNotImplemented(true);
+        ss = new StyleSheet();
+        doc = new HTMLDocument(ss);
+        doc.setAsynchronousLoadPriority(-1);
+        kit = new HTMLEditorKit();
+        StringReader reader = new StringReader("<html><head>\n" +
+                "<style type=\"text/css\">" +
+                ".par { font-style: italic; color: blue }" +
+                "</style>" +
+                "</head>\n" +
+                "\n" +
+                "<body>\n" +
+                "<p class=\"par\">The first paragraph has <code>class</code>" +
+                "                 attribute with value" +
+                "                 <code>&quot;par&quot;</code>.</p>\n" +
+                "<p class=\"par\">Also does the second one.</p>\n" +
+                "<p>While the third paragraph has no attributes.</p>\n" +
+                "</body></html>");
+        kit.read(reader, doc, 0);
+    }
+
+    public void testGetRule() {
+        p = doc.getParagraphElement(1);
+        assertEquals(1, p.getStartOffset());
+        assertEquals(59, p.getEndOffset());
+
+        rule = ss.getRule(Tag.P, p);
+        assertEquals("html body p.par", rule.getName());
+        assertEquals(3, rule.getAttributeCount());
+        assertEquals(".par", rule.getAttribute(AttributeSet.NameAttribute));
+    }
+
+    public void testGetRuleSame() {
+        p = doc.getParagraphElement(59);
+        assertEquals(59, p.getStartOffset());
+        assertEquals(85, p.getEndOffset());
+        assertEquals("par",
+                     p.getAttributes().getAttribute(HTML.Attribute.CLASS));
+
+        rule = ss.getRule(Tag.P, p);
+        assertEquals("html body p.par", rule.getName());
+        assertEquals(3, rule.getAttributeCount());
+        assertEquals(".par", rule.getAttribute(AttributeSet.NameAttribute));
+
+        Element firstP = doc.getParagraphElement(1);
+        assertEquals(1, firstP.getStartOffset());
+        assertEquals(59, firstP.getEndOffset());
+        assertEquals("par",
+                     firstP.getAttributes().getAttribute(HTML.Attribute.CLASS));
+
+        Style firstPRule = ss.getRule(Tag.P, firstP);
+        assertEquals("html body p.par", rule.getName());
+        assertEquals(3, rule.getAttributeCount());
+        assertEquals(".par", rule.getAttribute(AttributeSet.NameAttribute));
+
+        assertSame(rule, firstPRule);
+    }
+
+    public void testGetRuleAutoChange() {
+        p = doc.getParagraphElement(1);
+        assertEquals(1, p.getStartOffset());
+        assertEquals(59, p.getEndOffset());
+
+        rule = ss.getRule(Tag.P, p);
+        assertEquals("html body p.par", rule.getName());
+        assertEquals(3, rule.getAttributeCount());
+
+        ss.addRule("p { background-color: yellow }");
+
+        assertEquals("html body p.par", rule.getName());
+        assertEquals(5, rule.getAttributeCount());
+        assertEquals(".par", rule.getAttribute(AttributeSet.NameAttribute));
+    }
+
+    public void testGetRuleOL_LI() throws Exception {
+        reInit();
+
+        Element li = doc.getParagraphElement(1).getParentElement();
+        assertEquals("li", li.getName());
+        assertEquals(1, li.getStartOffset());
+        assertEquals(13, li.getEndOffset());
+
+        rule = ss.getRule(Tag.LI, li);
+        assertEquals("html body ol li.first", rule.getName());
+        assertEquals(3, rule.getAttributeCount());
+        assertEquals(".first", rule.getAttribute(AttributeSet.NameAttribute));
+    }
+
+    public void testGetRuleUL_LI() throws Exception {
+        reInit();
+
+        Element li = doc.getParagraphElement(22).getParentElement();
+        assertEquals("li", li.getName());
+        assertEquals(22, li.getStartOffset());
+        assertEquals(34, li.getEndOffset());
+
+        rule = ss.getRule(Tag.LI, li);
+        assertEquals("html body ul li.first", rule.getName());
+        assertEquals(3, rule.getAttributeCount());
+        assertEquals(".first", rule.getAttribute(AttributeSet.NameAttribute));
+    }
+
+    private void reInit() throws Exception {
+        ss = new StyleSheet();
+        doc = new HTMLDocument(ss);
+        doc.setAsynchronousLoadPriority(-1);
+        StringReader reader = new StringReader("<html><head>\n" +
+                "<style type=\"text/css\">" +
+                ".first { font-style: italic; color: blue }" +
+                "</style>" +
+                "</head>\n" +
+                "\n" +
+                "<body>\n" +
+                "<ol>\n" +
+                "    <li class=\"first\">first class</li>\n" +
+                "    <li>no class</li>\n" +
+                "</ol>\n" +
+                "\n" +
+                "<ul>\n" +
+                "    <li class=\"first\">first class</li>\n" +
+                "    <li>no class</li>\n" +
+                "</ul>\n" +
+                "</body></html>");
+        kit.read(reader, doc, 0);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ResolvedRulesTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ResolvedRulesTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ResolvedRulesTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ResolvedRulesTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,451 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Alexey A. Ivanov
+ * @version $Revision$
+ */
+package javax.swing.text.html;
+
+import java.io.StringReader;
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+
+import javax.swing.BasicSwingTestCase;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.Element;
+import javax.swing.text.Style;
+import javax.swing.text.html.CSS.Attribute;
+import javax.swing.text.html.HTML.Tag;
+
+public class StyleSheet_ResolvedRulesTest extends BasicSwingTestCase {
+    private static final int P_EM_START_OFFSET = 20;
+    private static final int PSMALL_EM_START_OFFSET = 82;
+
+    private HTMLDocument doc;
+    private StyleSheet ss;
+    private Style rule;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        setIgnoreNotImplemented(true);
+        ss = new StyleSheet();
+        doc = new HTMLDocument(ss);
+        doc.setAsynchronousLoadPriority(-1);
+        HTMLEditorKit kit = new HTMLEditorKit();
+        StringReader reader = new StringReader("<html><head><style>\n" +
+                "body { font-family: serif; font-size: large }\n" +
+                "p { text-indent: 10pt }\n" +
+                "p.small { font-size: small}\n" +
+                "p.small em {color: red}" +
+                "</style></head>" +
+                "<body>" +
+                "<p>Normal paragraph: <em>em inside</em>" +
+                "   paragraph." +
+                "<p class=\"small\">Paragraph with small class also contains" +
+                "   <em>em tag</em> which should be in red." +
+                "</body></html>");
+        kit.read(reader, doc, 0);
+    }
+
+    public void testGetRuleTagElement_NoContext() {
+        Element em = doc.getCharacterElement(P_EM_START_OFFSET);
+        assertNotNull(em.getAttributes().getAttribute(Tag.EM));
+
+        rule = ss.getRule(Tag.EM, em);
+        assertEquals(0, rule.getAttributeCount());
+        assertEquals("html body p em", rule.getName());
+    }
+
+    public void testGetRuleTagElement_NoContext_Same() {
+        Element em = doc.getCharacterElement(P_EM_START_OFFSET);
+        assertNotNull(em.getAttributes().getAttribute(Tag.EM));
+
+        rule = ss.getRule(Tag.EM, em);
+        assertSame(rule, ss.getRule(Tag.EM, em));
+    }
+
+    public void testGetRuleTagElement_Context() {
+        Element em = doc.getCharacterElement(PSMALL_EM_START_OFFSET);
+        assertNotNull(em.getAttributes().getAttribute(Tag.EM));
+
+        rule = ss.getRule(Tag.EM, em);
+        assertEquals(2, rule.getAttributeCount());
+        assertEquals("red", rule.getAttribute(Attribute.COLOR).toString());
+        assertEquals("p.small em",
+                     rule.getAttribute(AttributeSet.NameAttribute));
+        assertEquals("html body p.small em", rule.getName());
+    }
+
+    public void testGetRuleTagElement_Context_Same() {
+        Element em = doc.getCharacterElement(PSMALL_EM_START_OFFSET);
+        assertNotNull(em.getAttributes().getAttribute(Tag.EM));
+
+        rule = ss.getRule(Tag.EM, em);
+        assertSame(rule, ss.getRule(Tag.EM, em));
+    }
+
+    public void testGetRuleTagElement_AutoChange_NoContext() {
+        Element em = doc.getCharacterElement(P_EM_START_OFFSET);
+        assertNotNull(em.getAttributes().getAttribute(Tag.EM));
+
+        rule = ss.getRule(Tag.EM, em);
+        assertEquals(0, rule.getAttributeCount());
+
+        ss.addRule("em { background-color: rgb(255, 255, 150) }");
+        assertEquals(2, rule.getAttributeCount());
+        assertEquals("rgb(255, 255, 150)",
+                     rule.getAttribute(Attribute.BACKGROUND_COLOR)
+                     .toString());
+        assertEquals("em",
+                     rule.getAttribute(AttributeSet.NameAttribute));
+    }
+
+    public void testGetRuleTagElement_AutoChange_NoContextOverride() {
+        Element em = doc.getCharacterElement(P_EM_START_OFFSET);
+        assertNotNull(em.getAttributes().getAttribute(Tag.EM));
+
+        rule = ss.getRule(Tag.EM, em);
+        assertEquals(0, rule.getAttributeCount());
+
+        ss.addRule("em { color: rgb(127, 0, 0) }");
+        assertEquals(2, rule.getAttributeCount());
+        assertEquals("rgb(127, 0, 0)",
+                     rule.getAttribute(Attribute.COLOR).toString());
+        assertEquals("em",
+                     rule.getAttribute(AttributeSet.NameAttribute));
+    }
+
+    public void testGetRuleTagElement_AutoChange_Context() {
+        Element em = doc.getCharacterElement(PSMALL_EM_START_OFFSET);
+        assertNotNull(em.getAttributes().getAttribute(Tag.EM));
+
+        rule = ss.getRule(Tag.EM, em);
+        assertEquals(2, rule.getAttributeCount());
+
+        ss.addRule("em { background-color: rgb(255, 255, 150) }");
+        assertEquals(4, rule.getAttributeCount());
+        assertEquals("rgb(255, 255, 150)",
+                     rule.getAttribute(Attribute.BACKGROUND_COLOR)
+                     .toString());
+        assertEquals("red", rule.getAttribute(Attribute.COLOR).toString());
+        assertEquals("p.small em",
+                     rule.getAttribute(AttributeSet.NameAttribute));
+
+        assertEquals(2, getNameAttributeCount(rule));
+    }
+
+    public void testGetRuleTagElement_AutoChange_ContextOverride() {
+        Element em = doc.getCharacterElement(PSMALL_EM_START_OFFSET);
+        assertNotNull(em.getAttributes().getAttribute(Tag.EM));
+
+        rule = ss.getRule(Tag.EM, em);
+        assertEquals(2, rule.getAttributeCount());
+
+        ss.addRule("em { color: rgb(127, 0, 0) }");
+        assertEquals(4, rule.getAttributeCount());
+        assertEquals("red",
+                     rule.getAttribute(Attribute.COLOR).toString());
+        assertEquals("p.small em",
+                     rule.getAttribute(AttributeSet.NameAttribute));
+
+        assertEquals(2, getNameAttributeCount(rule));
+        assertEquals(2, getAttributeCount(rule, Attribute.COLOR));
+    }
+
+    public void testGetRuleTagElement_AutoChange_ChangeStyle() {
+        Element em = doc.getCharacterElement(PSMALL_EM_START_OFFSET);
+        assertNotNull(em.getAttributes().getAttribute(Tag.EM));
+
+        rule = ss.getRule(Tag.EM, em);
+        assertEquals(2, rule.getAttributeCount());
+
+        ss.addCSSAttribute(rule, Attribute.BACKGROUND_COLOR, "#FFFFFF");
+        assertEquals(2, rule.getAttributeCount());
+        assertNull(rule.getAttribute(Attribute.BACKGROUND_COLOR));
+
+        ss.addRule("em { color: rgb(127, 0, 0) }");
+        assertEquals(4, rule.getAttributeCount());
+        assertEquals("red",
+                     rule.getAttribute(Attribute.COLOR).toString());
+        assertEquals("p.small em",
+                     rule.getAttribute(AttributeSet.NameAttribute));
+
+        assertEquals(2, getNameAttributeCount(rule));
+        assertEquals(2, getAttributeCount(rule, Attribute.COLOR));
+    }
+
+    public void testGetRuleTagElement_AutoChange_ChangeStyle_Override() {
+        Element em = doc.getCharacterElement(PSMALL_EM_START_OFFSET);
+        assertNotNull(em.getAttributes().getAttribute(Tag.EM));
+
+        rule = ss.getRule(Tag.EM, em);
+        assertEquals(2, rule.getAttributeCount());
+
+        ss.addCSSAttribute(rule, Attribute.COLOR, "#000000");
+        assertEquals(2, rule.getAttributeCount());
+        assertEquals("red", rule.getAttribute(Attribute.COLOR).toString());
+
+        ss.addRule("em { color: rgb(127, 0, 0) }");
+        assertEquals(4, rule.getAttributeCount());
+        assertEquals("red",
+                     rule.getAttribute(Attribute.COLOR).toString());
+        assertEquals("p.small em",
+                     rule.getAttribute(AttributeSet.NameAttribute));
+
+        assertEquals(2, getNameAttributeCount(rule));
+        assertEquals(2, getAttributeCount(rule, Attribute.COLOR));
+    }
+
+    public void testGetRuleTagElement_AddStyle() {
+        Element em = doc.getCharacterElement(P_EM_START_OFFSET);
+        assertNotNull(em.getAttributes().getAttribute(Tag.EM));
+
+        assertEquals(5, getStyleNumber());
+        assertNull(ss.getStyle("em"));
+
+        rule = ss.getRule(Tag.EM, em);
+        assertEquals("html body p em", rule.getName());
+        assertEquals(0, rule.getAttributeCount());
+
+        assertEquals(5, getStyleNumber());
+        assertNull(ss.getStyle("em"));
+    }
+
+    public void testGetRuleString_AddStyle() {
+        assertEquals(5, getStyleNumber());
+        assertNull(ss.getStyle("em"));
+
+        rule = ss.getRule("em");
+        assertEquals("em", rule.getName());
+        assertEquals(0, rule.getAttributeCount());
+
+        assertEquals(5, getStyleNumber());
+        assertNull(ss.getStyle("em"));
+    }
+
+    public void testGetRule_NotSame() {
+        Element em = doc.getCharacterElement(P_EM_START_OFFSET); // With no context associated
+        assertNotNull(em.getAttributes().getAttribute(Tag.EM));
+
+        rule = ss.getRule(Tag.EM, em);
+        Style ruleEm = ss.getRule("em");
+        assertNotSame(rule, ruleEm);
+        assertEquals("html body p em", rule.getName());
+        assertEquals("em", ruleEm.getName());
+    }
+
+    public void testGetRule_Same() {
+        Element em = doc.getCharacterElement(P_EM_START_OFFSET); // With no context associated
+        assertNotNull(em.getAttributes().getAttribute(Tag.EM));
+
+        rule = ss.getRule(Tag.EM, em);
+        assertEquals("html body p em", rule.getName());
+        assertSame(rule, ss.getRule("html body p em"));
+    }
+
+    public void testGetRule_Same_Context() {
+        Element em = doc.getCharacterElement(PSMALL_EM_START_OFFSET); // With context associated
+        assertNotNull(em.getAttributes().getAttribute(Tag.EM));
+
+        rule = ss.getRule(Tag.EM, em);
+        assertEquals("html body p.small em", rule.getName());
+        assertSame(rule, ss.getRule("html body p.small em"));
+    }
+
+    public void testGetRuleString_NoContext() {
+        rule = ss.getRule("em");
+        assertEquals(0, rule.getAttributeCount());
+    }
+
+    public void testGetRuleString_ContextClass() {
+        rule = ss.getRule("p.small em");
+        assertEquals(2, rule.getAttributeCount());
+    }
+
+    public void testGetRuleString_ContextNoClass() {
+        ss.addRule("p em { text-decoration: underline }");
+        rule = ss.getRule("p em");
+        assertEquals(2, rule.getAttributeCount());
+
+        assertEquals("underline",
+                     rule.getAttribute(Attribute.TEXT_DECORATION).toString());
+        assertEquals("p em",
+                     rule.getAttribute(AttributeSet.NameAttribute));
+    }
+
+    public void testGetRuleString_Autochange_ContextNoClass01() {
+        ss.addRule("p em { text-decoration: underline }");
+        rule = ss.getRule("p em");
+        assertEquals(2, rule.getAttributeCount());
+
+        ss.addRule("em { color: rgb(127, 0, 0) }");
+        assertEquals(4, rule.getAttributeCount());
+        assertEquals("rgb(127, 0, 0)",
+                     rule.getAttribute(Attribute.COLOR).toString());
+        assertEquals("underline",
+                     rule.getAttribute(Attribute.TEXT_DECORATION).toString());
+        assertEquals("p em",
+                     rule.getAttribute(AttributeSet.NameAttribute));
+
+        assertEquals(2, getNameAttributeCount(rule));
+    }
+
+    public void testGetRuleString_Autochange_ContextNoClass02() {
+        ss.addRule("p em { text-decoration: underline }");
+        rule = ss.getRule("p em");
+        assertEquals(2, rule.getAttributeCount());
+
+        ss.addRule("p em { color: rgb(50%, 100%, 50%) }");
+        assertEquals(3, rule.getAttributeCount());
+        assertEquals("rgb(50%, 100%, 50%)",
+                     rule.getAttribute(Attribute.COLOR).toString());
+        assertEquals("underline",
+                     rule.getAttribute(Attribute.TEXT_DECORATION).toString());
+        assertEquals("p em",
+                     rule.getAttribute(AttributeSet.NameAttribute));
+    }
+
+    public void testGetRuleString_AutoChange_NoContext() {
+        rule = ss.getRule("em");
+        assertEquals(0, rule.getAttributeCount());
+
+        ss.addRule("em { color: rgb(127, 0, 0) }");
+        assertEquals(2, rule.getAttributeCount());
+        assertEquals("rgb(127, 0, 0)",
+                     rule.getAttribute(Attribute.COLOR).toString());
+        assertEquals("em",
+                     rule.getAttribute(AttributeSet.NameAttribute));
+    }
+
+    public void testGetRuleTagElement_Listeners() {
+        Element em = doc.getCharacterElement(P_EM_START_OFFSET);
+        assertNotNull(em.getAttributes().getAttribute(Tag.EM));
+
+        rule = ss.getRule(Tag.EM, em);
+        assertEquals(0, rule.getAttributeCount());
+        final boolean[] happened = new boolean[1];
+        ChangeListener listener = new ChangeListener() {
+            public void stateChanged(final ChangeEvent e) {
+                happened[0] = true;
+            }
+        };
+        rule.addChangeListener(listener);
+
+        ss.addRule("em { background-color: rgb(255, 255, 150) }");
+        assertEquals(2, rule.getAttributeCount());
+        assertFalse(happened[0]);
+
+        Style emStyle = ss.getStyle("em");
+        ss.addCSSAttribute(emStyle, CSS.Attribute.COLOR, "black");
+        assertEquals(3, rule.getAttributeCount());
+        assertFalse(happened[0]);
+    }
+
+    public void testGetRuleTagElement_RemoveStyle() {
+        Element em = doc.getCharacterElement(P_EM_START_OFFSET);
+        assertNotNull(em.getAttributes().getAttribute(Tag.EM));
+
+        ss.addRule("em { color: rgb(255, 255, 150) }");
+
+        rule = ss.getRule(Tag.EM, em);
+        assertEquals(2, rule.getAttributeCount());
+        assertEquals("rgb(255, 255, 150)",
+                     rule.getAttribute(Attribute.COLOR).toString());
+
+        ss.removeStyle("em");
+        assertEquals(0, rule.getAttributeCount());
+        assertNull(rule.getAttribute(Attribute.COLOR));
+    }
+
+    public void testGetRuleString_Partial() {
+        ss.addRule("em { color: rgb(255, 255, 150) }");
+
+        rule = ss.getRule("em");
+
+        Style qualifiedRule = ss.getRule("html body p em");
+        assertNotSame(rule, qualifiedRule);
+        assertTrue(rule.isEqual(qualifiedRule));
+        assertEquals(2, qualifiedRule.getAttributeCount());
+        assertEquals("rgb(255, 255, 150)",
+                     qualifiedRule.getAttribute(Attribute.COLOR).toString());
+    }
+
+    public void testGetRuleString_NoRules() {
+        rule = ss.getRule(HTML.Tag.ADDRESS.toString());
+
+        assertEquals(0, rule.getAttributeCount());
+        final Enumeration keys = rule.getAttributeNames();
+        assertFalse(keys.hasMoreElements());
+
+        testExceptionalCase(new ExceptionalCase() {
+            public void exceptionalAction() throws Exception {
+                keys.nextElement();
+            }
+
+            public Class expectedExceptionClass() {
+                return NoSuchElementException.class;
+            }
+        });
+    }
+
+    public void testGetRuleString_NoRulesStyles() {
+        ss.addStyleSheet(new StyleSheet());
+        rule = ss.getRule(HTML.Tag.ADDRESS.toString());
+
+        assertEquals(0, rule.getAttributeCount());
+        final Enumeration keys = rule.getAttributeNames();
+        assertFalse(keys.hasMoreElements());
+
+        testExceptionalCase(new ExceptionalCase() {
+            public void exceptionalAction() throws Exception {
+                keys.nextElement();
+            }
+
+            public Class expectedExceptionClass() {
+                return NoSuchElementException.class;
+            }
+        });
+    }
+
+    private static int getAttributeCount(final AttributeSet rule,
+                                         final Object attrKey) {
+        int result = 0;
+        Enumeration keys = rule.getAttributeNames();
+        while (keys.hasMoreElements()) {
+            Object key = keys.nextElement();
+            if (attrKey.equals(key)) {
+                ++result;
+            }
+        }
+        return result;
+    }
+
+    private static int getNameAttributeCount(final AttributeSet rule) {
+        return getAttributeCount(rule, AttributeSet.NameAttribute);
+    }
+
+    private int getStyleNumber() {
+        int result = 0;
+        final Enumeration styleNames = ss.getStyleNames();
+        while (styleNames.hasMoreElements()) {
+            ++result;
+            styleNames.nextElement();
+        }
+        return result;
+    }
+}



Mime
View raw message