Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_BorderTopWidthTest.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_BorderTopWidthTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_BorderTopWidthTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_BorderTopWidthTest.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_BorderTopWidthTest
+ extends StyleSheet_ConvertAttr_BorderWidthTestCase {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ cssKey = CSS.Attribute.BORDER_TOP_WIDTH;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_BorderWidthTest.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_BorderWidthTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_BorderWidthTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_BorderWidthTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,35 @@
+/*
+ * 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_BorderWidthTest
+ extends StyleSheet_ConvertAttr_SpaceTestCase {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ shorthandKey = CSS.Attribute.BORDER_WIDTH;
+ topKey = CSS.Attribute.BORDER_TOP_WIDTH;
+ rightKey = CSS.Attribute.BORDER_RIGHT_WIDTH;
+ bottomKey = CSS.Attribute.BORDER_BOTTOM_WIDTH;
+ leftKey = CSS.Attribute.BORDER_LEFT_WIDTH;
+
+ defaultValue = "medium";
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_BorderWidthTestCase.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_BorderWidthTestCase.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_BorderWidthTestCase.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_BorderWidthTestCase.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,103 @@
+/*
+ * 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 abstract class StyleSheet_ConvertAttr_BorderWidthTestCase
+ extends StyleSheet_ConvertAttr_LengthTestCase {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ negativeValuesInvalid = true;
+ percentageValuesInvalid = true;
+ }
+
+ public void testBorderWidthThin() {
+ ss.addCSSAttribute(simple, cssKey, "thin");
+ cssValue = simple.getAttribute(cssKey);
+ assertEquals("thin", cssValue.toString());
+ }
+
+ public void testBorderWidthMedium() {
+ ss.addCSSAttribute(simple, cssKey, "medium");
+ cssValue = simple.getAttribute(cssKey);
+ assertEquals("medium", cssValue.toString());
+ }
+
+ public void testBorderWidthThick() {
+ ss.addCSSAttribute(simple, cssKey, "thick");
+ cssValue = simple.getAttribute(cssKey);
+ assertEquals("thick", cssValue.toString());
+ }
+
+ public void testBorderWidthSmall() {
+ ss.addCSSAttribute(simple, cssKey, "small");
+ cssValue = simple.getAttribute(cssKey);
+ if (!BasicSwingTestCase.isHarmony()) {
+ assertEquals(1, simple.getAttributeCount());
+ assertEquals("medium", simple.getAttribute(cssKey).toString());
+ return;
+ }
+ assertEquals(0, simple.getAttributeCount());
+ assertNull(cssValue);
+ }
+
+ public void testLength0_75em() {
+ if (!BasicSwingTestCase.isHarmony()) {
+ ss.addCSSAttribute(simple, cssKey, "0.75em");
+ assertEquals(1, simple.getAttributeCount());
+ assertEquals("medium", simple.getAttribute(cssKey).toString());
+ return;
+ }
+ super.testLength0_75em();
+ }
+
+ public void testLength1_25ex() {
+ if (!BasicSwingTestCase.isHarmony()) {
+ ss.addCSSAttribute(simple, cssKey, "1.25ex");
+ assertEquals(1, simple.getAttributeCount());
+ assertEquals("medium", simple.getAttribute(cssKey).toString());
+ return;
+ }
+ super.testLength1_25ex();
+ }
+
+ public void testLengthMinus11_1pt() {
+ negativeValuesInvalid = BasicSwingTestCase.isHarmony();
+ super.testLengthMinus11_1pt();
+ }
+
+ public void testLength11_1Percent() {
+ percentageValuesInvalid = BasicSwingTestCase.isHarmony();
+ super.testLength11_1Percent();
+ }
+
+ public void testLengthMinus11_1Percent() {
+ negativeValuesInvalid = BasicSwingTestCase.isHarmony();
+ percentageValuesInvalid = BasicSwingTestCase.isHarmony();
+ super.testLengthMinus11_1Percent();
+ }
+
+ public void testLengthPlus11_1Percent() {
+ percentageValuesInvalid = BasicSwingTestCase.isHarmony();
+ super.testLengthPlus11_1Percent();
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_ClearTest.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_ClearTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_ClearTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_ClearTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,75 @@
+/*
+ * 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_ClearTest 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 testClearNone() {
+ ss.addCSSAttribute(simple, Attribute.CLEAR, "none");
+ cssValue = simple.getAttribute(Attribute.CLEAR);
+ assertEquals("none", cssValue.toString());
+ }
+
+ public void testClearLeft() {
+ ss.addCSSAttribute(simple, Attribute.CLEAR, "left");
+ cssValue = simple.getAttribute(Attribute.CLEAR);
+ assertEquals("left", cssValue.toString());
+ }
+
+ public void testClearRight() {
+ ss.addCSSAttribute(simple, Attribute.CLEAR, "right");
+ cssValue = simple.getAttribute(Attribute.CLEAR);
+ assertEquals("right", cssValue.toString());
+ }
+
+ public void testClearBoth() {
+ ss.addCSSAttribute(simple, Attribute.CLEAR, "both");
+ cssValue = simple.getAttribute(Attribute.CLEAR);
+ assertEquals("both", cssValue.toString());
+ }
+
+ public void testClearInvalid() {
+ ss.addCSSAttribute(simple, Attribute.CLEAR, "top");
+ cssValue = simple.getAttribute(Attribute.CLEAR);
+ if (BasicSwingTestCase.isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ assertNull(cssValue);
+ } else {
+ assertEquals(1, simple.getAttributeCount());
+ assertEquals("top", cssValue.toString());
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_ColorTest.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_ColorTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_ColorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_ColorTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,496 @@
+/*
+ * 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.awt.Color;
+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_ColorTest 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 testColor() {
+ final Color color = new Color(0xAF11FA);
+ attr = ss.addAttribute(empty, StyleConstants.Foreground, color);
+
+ Enumeration names = attr.getAttributeNames();
+ Object name = names.nextElement();
+ assertSame(Attribute.class, name.getClass());
+ assertFalse(names.hasMoreElements());
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertSame(Color.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(Color.class, cssValue.getClass());
+ assertNotSame(scValue, cssValue);
+ assertFalse(scValue.equals(cssValue));
+ assertEquals("#af11fa", cssValue.toString());
+ assertEquals(color.toString(), scValue.toString());
+ assertEquals(color, scValue);
+ }
+
+ public void testColorString() {
+ if (!isHarmony()) {
+ testExceptionalCase(new ClassCastCase() {
+ public void exceptionalAction() throws Exception {
+ ss.addAttribute(empty, StyleConstants.Foreground,
+ "#AD66DA");
+ }
+ });
+ return;
+ }
+ attr = ss.addAttribute(empty, StyleConstants.Foreground, "#AD66DA");
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertSame(Color.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(Color.class, cssValue.getClass());
+ assertEquals("#AD66DA", cssValue.toString());
+ assertEquals(new Color(0xAD, 0x66, 0xDA), scValue);
+ }
+
+ public void testColorBLACKColor() {
+ attr = ss.addAttribute(empty, StyleConstants.Foreground, Color.BLACK);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertSame(Color.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(Color.class, cssValue.getClass());
+ assertNotSame(scValue, cssValue);
+ assertFalse(scValue.equals(cssValue));
+ assertEquals("#000000", cssValue.toString());
+ assertSame(Color.BLACK, scValue);
+ }
+
+ public void testColorWHITEColor() {
+ attr = ss.addAttribute(empty, StyleConstants.Foreground, Color.WHITE);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertSame(Color.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(Color.class, cssValue.getClass());
+ assertNotSame(scValue, cssValue);
+ assertFalse(scValue.equals(cssValue));
+ assertEquals("#ffffff", cssValue.toString());
+ assertSame(Color.WHITE, scValue);
+ }
+
+ public void testColorNonSC() {
+ attr = ss.addAttribute(empty, Attribute.COLOR, Color.WHITE);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ if (isHarmony()) {
+ assertSame(Color.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(Color.class, cssValue.getClass());
+ assertEquals("#ffffff", cssValue.toString());
+ } else {
+ assertNull(scValue);
+ assertSame(Color.class, cssValue.getClass());
+ assertEquals(Color.WHITE.toString(), cssValue.toString());
+ }
+ }
+
+
+ public void testBackgroundColor() {
+ final Color color = new Color(0xAF11FA);
+ attr = ss.addAttribute(empty, StyleConstants.Background, color);
+
+ Enumeration names = attr.getAttributeNames();
+ Object name = names.nextElement();
+ assertSame(Attribute.class, name.getClass());
+ assertFalse(names.hasMoreElements());
+
+ cssValue = attr.getAttribute(Attribute.BACKGROUND_COLOR);
+ scValue = attr.getAttribute(StyleConstants.Background);
+ assertSame(Color.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(Color.class, cssValue.getClass());
+ assertNotSame(scValue, cssValue);
+ assertFalse(scValue.equals(cssValue));
+ assertEquals("#af11fa", cssValue.toString());
+ assertEquals(color.toString(), scValue.toString());
+ }
+
+ public void testBackgroundColorString() {
+ if (!isHarmony()) {
+ testExceptionalCase(new ClassCastCase() {
+ public void exceptionalAction() throws Exception {
+ ss.addAttribute(empty, StyleConstants.Background,
+ "#AD66DA");
+ }
+ });
+ return;
+ }
+
+ attr = ss.addAttribute(empty, StyleConstants.Background, "#AD66DA");
+
+ cssValue = attr.getAttribute(Attribute.BACKGROUND_COLOR);
+ scValue = attr.getAttribute(StyleConstants.Background);
+ assertSame(Color.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(Color.class, cssValue.getClass());
+ assertEquals("#AD66DA", cssValue.toString());
+ assertEquals(new Color(0xAD, 0x66, 0xDA), scValue);
+ }
+
+ public void testBackgroundColorBLACKColor() {
+ attr = ss.addAttribute(empty, StyleConstants.Background, Color.BLACK);
+
+ cssValue = attr.getAttribute(Attribute.BACKGROUND_COLOR);
+ scValue = attr.getAttribute(StyleConstants.Background);
+ assertSame(Color.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(Color.class, cssValue.getClass());
+ assertNotSame(scValue, cssValue);
+ assertFalse(scValue.equals(cssValue));
+ assertEquals("#000000", cssValue.toString());
+ assertSame(Color.BLACK, scValue);
+ }
+
+ public void testBackgroundColorWHITEColor() {
+ attr = ss.addAttribute(empty, StyleConstants.Background, Color.WHITE);
+
+ cssValue = attr.getAttribute(Attribute.BACKGROUND_COLOR);
+ scValue = attr.getAttribute(StyleConstants.Background);
+ assertSame(Color.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(Color.class, cssValue.getClass());
+ assertNotSame(scValue, cssValue);
+ assertFalse(scValue.equals(cssValue));
+ assertEquals("#ffffff", cssValue.toString());
+ assertSame(Color.WHITE, scValue);
+ }
+
+ public void testBackgroundColorNonSC() {
+ attr = ss.addAttribute(empty, Attribute.BACKGROUND_COLOR, Color.WHITE);
+
+ cssValue = attr.getAttribute(Attribute.BACKGROUND_COLOR);
+ scValue = attr.getAttribute(StyleConstants.Background);
+ if (isHarmony()) {
+ assertSame(Color.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(Color.class, cssValue.getClass());
+ assertEquals("#ffffff", cssValue.toString());
+ } else {
+ assertNull(scValue);
+ assertSame(Color.class, cssValue.getClass());
+ assertEquals(Color.WHITE.toString(), cssValue.toString());
+ }
+ }
+
+
+
+ public void testColorRed01() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "red");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertSame(Color.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(Color.class, cssValue.getClass());
+ assertEquals("red", cssValue.toString());
+ if (isHarmony()) {
+ assertSame(Color.RED, scValue);
+ } else {
+ assertEquals(Color.RED, scValue);
+ }
+ }
+
+ public void testColorRed02() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "Red");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("Red", cssValue.toString());
+ if (isHarmony()) {
+ assertSame(Color.RED, scValue);
+ } else {
+ assertEquals(Color.RED, scValue);
+ }
+ }
+
+ public void testColorRed03() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "ReD");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("ReD", cssValue.toString());
+ if (isHarmony()) {
+ assertSame(Color.RED, scValue);
+ } else {
+ assertEquals(Color.RED, scValue);
+ }
+ }
+
+ public void testColorRed04() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "rEd");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("rEd", cssValue.toString());
+ if (isHarmony()) {
+ assertSame(Color.RED, scValue);
+ } else {
+ assertEquals(Color.RED, scValue);
+ }
+ }
+
+ public void testColorRed05() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "RED");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("RED", cssValue.toString());
+ if (isHarmony()) {
+ assertSame(Color.RED, scValue);
+ } else {
+ assertEquals(Color.RED, scValue);
+ }
+ }
+
+ public void testColorStringUnknown() throws Exception {
+ if (!isHarmony()) {
+ testExceptionalCase(new NullPointerCase() {
+ public void exceptionalAction() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "unknown");
+ }
+ });
+ return;
+ }
+ assertEquals(0, simple.getAttributeCount());
+ ss.addCSSAttribute(simple, Attribute.COLOR, "unknown");
+ // No attribute was added
+ assertEquals(0, simple.getAttributeCount());
+ }
+
+ public void testColorRGB255_0_0() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "rgb(255, 0, 0)");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertSame(Color.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(Color.class, cssValue.getClass());
+ assertEquals("rgb(255, 0, 0)", cssValue.toString());
+ assertEquals(Color.RED, scValue);
+ }
+
+ public void testColorRGB255_0_0NoSpace() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "rgb(255,0,0)");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("rgb(255,0,0)", cssValue.toString());
+ assertEquals(Color.RED, scValue);
+ }
+
+ public void testColorRGB255_0_0MoreSpace() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR,
+ "rgb( 255 , 0 , 0 )");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("rgb( 255 , 0 , 0 )", cssValue.toString());
+ assertEquals(Color.RED, scValue);
+ }
+
+ public void testColorRGB0_300_0() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "rgb(0, 300, 0)");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("rgb(0, 300, 0)", cssValue.toString());
+ assertEquals(Color.GREEN, scValue);
+ }
+
+ public void testColorRGBMinus25_127_0() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "rgb(-25, 127, 0)");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("rgb(-25, 127, 0)", cssValue.toString());
+ assertEquals(new Color(0, 127, 0), scValue);
+ }
+
+ public void testColorRGBIntPercent0_0_100() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "rgb(0%, 0%, 100%)");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("rgb(0%, 0%, 100%)", cssValue.toString());
+ assertEquals(Color.BLUE, scValue);
+ }
+
+ public void testColorRGBIntPercent0_50_100() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "rgb(0%, 50%, 100%)");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("rgb(0%, 50%, 100%)", cssValue.toString());
+ assertEquals(new Color(0, 255 / 2, 255), scValue);
+ }
+
+ public void testColorRGBIntPercent0_50_200() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "rgb(0%, 50%, 200%)");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("rgb(0%, 50%, 200%)", cssValue.toString());
+ assertEquals(new Color(0, 255 / 2, 255), scValue);
+ }
+
+ public void testColorRGBIntPercentMinus25_50_75() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "rgb(-25%, 50%, 75%)");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("rgb(-25%, 50%, 75%)", cssValue.toString());
+ assertEquals(new Color(0, 255 / 2, 255 * 3 / 4), scValue);
+ }
+
+ public void testColorRGBFloatPercent1p5_0_100() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "rgb(1.5%, 0%, 100.00%)");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("rgb(1.5%, 0%, 100.00%)", cssValue.toString());
+ assertEquals((int)(255 * 0.01) + 1, (int)(255 * 0.015));
+ assertEquals(new Color((int)(255 * 0.015), 0, 255), scValue);
+ }
+
+ public void testColorRGBFloatPercent1p2_0_100() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "rgb(1.1%, 0%, 100.00%)");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("rgb(1.1%, 0%, 100.00%)", cssValue.toString());
+ assertEquals((int)(255 * 0.01), (int)(255 * 0.011));
+ assertEquals(new Color((int)(255 * 0.011), 0, 255), scValue);
+ }
+
+ public void testColorRGBFloatPercent0_50p5_100() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "rgb(0.000%, 50.5%, 100%)");
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("rgb(0.000%, 50.5%, 100%)", cssValue.toString());
+ assertEquals((int)(255 * 0.5) + 1, (int)(255 * 0.505));
+ assertEquals(new Color(0, (int)(255 * 0.505), 255), scValue);
+ }
+
+ public void testColorRGBNumberMissed() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "rgb(127, , 255)");
+ if (isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ return;
+ }
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("rgb(127, , 255)", cssValue.toString());
+ assertEquals(new Color(127, 255, 0), scValue);
+ }
+
+ public void testColorRGBCommaMissed() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "rgb(127, 0 255)");
+ if (isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ return;
+ }
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("rgb(127, 0 255)", cssValue.toString());
+ assertEquals(new Color(127, 0, 255), scValue);
+ }
+
+ public void testColorRGBAbsolutePercentangeMixed() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.COLOR, "rgb(50%, 0, 255)");
+ if (isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ return;
+ }
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.COLOR);
+ scValue = attr.getAttribute(StyleConstants.Foreground);
+ assertEquals("rgb(50%, 0, 255)", cssValue.toString());
+ assertEquals(new Color(127, 0, 255), scValue);
+ }
+
+
+
+ public void testBackgroundColorTransparent() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.BACKGROUND_COLOR, "transparent");
+ if (!isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ return;
+ }
+ attr = ss.createSmallAttributeSet(simple);
+
+ cssValue = attr.getAttribute(Attribute.BACKGROUND_COLOR);
+ scValue = attr.getAttribute(StyleConstants.Background);
+ assertEquals("transparent", cssValue.toString());
+ assertNull(scValue);
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_DisplayTest.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_DisplayTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_DisplayTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_DisplayTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,75 @@
+/*
+ * 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_DisplayTest 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 testDisplayNone() {
+ ss.addCSSAttribute(simple, Attribute.DISPLAY, "none");
+ cssValue = simple.getAttribute(Attribute.DISPLAY);
+ assertEquals("none", cssValue.toString());
+ }
+
+ public void testDisplayBlock() {
+ ss.addCSSAttribute(simple, Attribute.DISPLAY, "block");
+ cssValue = simple.getAttribute(Attribute.DISPLAY);
+ assertEquals("block", cssValue.toString());
+ }
+
+ public void testDisplayInline() {
+ ss.addCSSAttribute(simple, Attribute.DISPLAY, "inline");
+ cssValue = simple.getAttribute(Attribute.DISPLAY);
+ assertEquals("inline", cssValue.toString());
+ }
+
+ public void testDisplayListItem() {
+ ss.addCSSAttribute(simple, Attribute.DISPLAY, "list-item");
+ cssValue = simple.getAttribute(Attribute.DISPLAY);
+ assertEquals("list-item", cssValue.toString());
+ }
+
+ public void testDisplayInvalid() {
+ ss.addCSSAttribute(simple, Attribute.DISPLAY, "inline-block"); // CSS 2
+ cssValue = simple.getAttribute(Attribute.DISPLAY);
+ if (BasicSwingTestCase.isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ assertNull(cssValue);
+ } else {
+ assertEquals(1, simple.getAttributeCount());
+ assertEquals("inline-block", cssValue.toString());
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FloatTest.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_FloatTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FloatTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FloatTest.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_FloatTest 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 testFloatNone() {
+ ss.addCSSAttribute(simple, Attribute.FLOAT, "none");
+ cssValue = simple.getAttribute(Attribute.FLOAT);
+ assertEquals("none", cssValue.toString());
+ }
+
+ public void testFloatLeft() {
+ ss.addCSSAttribute(simple, Attribute.FLOAT, "left");
+ cssValue = simple.getAttribute(Attribute.FLOAT);
+ assertEquals("left", cssValue.toString());
+ }
+
+ public void testFloatRight() {
+ ss.addCSSAttribute(simple, Attribute.FLOAT, "right");
+ cssValue = simple.getAttribute(Attribute.FLOAT);
+ assertEquals("right", cssValue.toString());
+ }
+
+ public void testFloatInvalid() {
+ ss.addCSSAttribute(simple, Attribute.FLOAT, "top");
+ cssValue = simple.getAttribute(Attribute.FLOAT);
+ if (BasicSwingTestCase.isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ assertNull(cssValue);
+ } else {
+ assertEquals(1, simple.getAttributeCount());
+ assertEquals("top", cssValue.toString());
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FontFamilyTest.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_FontFamilyTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FontFamilyTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FontFamilyTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,331 @@
+/*
+ * 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.awt.GraphicsEnvironment;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.List;
+
+import javax.swing.BasicSwingTestCase;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.html.CSS.Attribute;
+
+public class StyleSheet_ConvertAttr_FontFamilyTest extends BasicSwingTestCase {
+ private StyleSheet ss;
+ private AttributeSet empty;
+ private AttributeSet attr;
+ private Object cssValue;
+ private Object scValue;
+ private static final String[] fonts;
+ private static final List fontList;
+
+ static {
+ GraphicsEnvironment ge =
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
+ fonts = ge.getAvailableFontFamilyNames();
+ fontList = Arrays.asList(fonts);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ ss = new StyleSheet();
+ empty = ss.getEmptySet();
+ }
+
+ /**
+ * Contains a known font on Windows.
+ */
+ public void testFontFamilyW() {
+ attr = ss.addAttribute(empty, StyleConstants.FontFamily, "Arial");
+ Enumeration names = attr.getAttributeNames();
+ Object name = names.nextElement();
+ assertSame(Attribute.class, name.getClass());
+ assertFalse(names.hasMoreElements());
+
+ cssValue = attr.getAttribute(name);
+ scValue = attr.getAttribute(StyleConstants.FontFamily);
+ assertSame(String.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(scValue, cssValue);
+ assertFalse(scValue.equals(cssValue));
+ if (fontList.contains("Arial")) {
+ assertEquals("Arial", scValue.toString());
+ } else {
+ assertEquals("SansSerif", scValue.toString());
+ }
+ }
+
+ /**
+ * Contains a known font on Linux.
+ */
+ public void testFontFamilyL() {
+ attr = ss.addAttribute(empty, StyleConstants.FontFamily, "Lucida Sans");
+ Enumeration names = attr.getAttributeNames();
+ Object name = names.nextElement();
+ assertSame(Attribute.class, name.getClass());
+ assertFalse(names.hasMoreElements());
+
+ cssValue = attr.getAttribute(Attribute.FONT_FAMILY);
+ scValue = attr.getAttribute(StyleConstants.FontFamily);
+ assertSame(String.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(scValue, cssValue);
+ assertFalse(scValue.equals(cssValue));
+ if (fontList.contains("Lucida Sans")) {
+ assertEquals("Lucida Sans", scValue.toString());
+ } else {
+ assertEquals("SansSerif", scValue.toString());
+ }
+ }
+
+ /**
+ * The value refers to the unknown font.
+ */
+ public void testFontFamilyNotExists() {
+ attr = ss.addAttribute(empty, StyleConstants.FontFamily, "Helvet");
+
+ cssValue = attr.getAttribute(Attribute.FONT_FAMILY);
+ scValue = attr.getAttribute(StyleConstants.FontFamily);
+ assertSame(String.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(scValue, cssValue);
+ assertFalse(scValue.equals(cssValue));
+ assertEquals("Helvet", cssValue.toString());
+ assertEquals("SansSerif", scValue.toString());
+ }
+
+ /**
+ * Multiple fonts are listed.
+ * The name of the first font found on the system is returned as result
+ * of the convertion.
+ */
+ public void testFontFamilyMultiple() {
+ GraphicsEnvironment ge =
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
+ List fontList = Arrays.asList(ge.getAvailableFontFamilyNames());
+ boolean hasGaramond = fontList.contains("Garamond");
+ boolean hasTimes = fontList.contains("Times New Roman");
+
+ attr = ss.addAttribute(empty, StyleConstants.FontFamily,
+ "Garamond, Times New Roman, serif");
+
+ cssValue = attr.getAttribute(Attribute.FONT_FAMILY);
+ scValue = attr.getAttribute(StyleConstants.FontFamily);
+ assertSame(String.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(scValue, cssValue);
+ assertFalse(scValue.equals(cssValue));
+ assertEquals("Garamond, Times New Roman, serif", cssValue.toString());
+ if (hasGaramond) {
+ assertEquals("Garamond", scValue.toString());
+ } else if (hasTimes) {
+ assertEquals("Times New Roman", scValue.toString());
+ } else {
+ assertEquals(isHarmony() ? "Serif" : "SansSerif", scValue.toString());
+ }
+ }
+
+ /**
+ * Multiple fonts are listed. The first item refers to non-existent font,
+ * the second to the known font on Windows systems.
+ */
+ public void testFontFamilyMultipleNonExistentW() {
+ GraphicsEnvironment ge =
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
+ List fontList = Arrays.asList(ge.getAvailableFontFamilyNames());
+ boolean hasTimes = fontList.contains("Times New Roman");
+
+ attr = ss.addAttribute(empty, StyleConstants.FontFamily,
+ "NonExistentFont, Times New Roman, serif");
+
+ cssValue = attr.getAttribute(Attribute.FONT_FAMILY);
+ scValue = attr.getAttribute(StyleConstants.FontFamily);
+ assertSame(String.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(scValue, cssValue);
+ assertFalse(scValue.equals(cssValue));
+ assertEquals("NonExistentFont, Times New Roman, serif", cssValue.toString());
+ if (hasTimes) {
+ // The test is expected to be here when run on Windows
+ assertEquals(isHarmony() ? "Times New Roman" : "SansSerif",
+ scValue.toString());
+ } else {
+ assertEquals(isHarmony() ? "Serif" : "SansSerif",
+ scValue.toString());
+ }
+ }
+
+ /**
+ * Multiple fonts are listed. The first item refers to non-existent font,
+ * the second to the known font on Linux systems.
+ */
+ public void testFontFamilyMultipleNonExistentL() {
+ boolean hasLucida = fontList.contains("Lucida Sans");
+
+ attr = ss.addAttribute(empty, StyleConstants.FontFamily,
+ "NonExistentFont, Lucida Sans, serif");
+
+ cssValue = attr.getAttribute(Attribute.FONT_FAMILY);
+ scValue = attr.getAttribute(StyleConstants.FontFamily);
+ assertSame(String.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(scValue, cssValue);
+ assertFalse(scValue.equals(cssValue));
+ assertEquals("NonExistentFont, Lucida Sans, serif",
+ cssValue.toString());
+ if (hasLucida) {
+ // The test is expected to be here when run on Linux
+ assertEquals(isHarmony() ? "Lucida Sans" : "SansSerif",
+ scValue.toString());
+ } else {
+ assertEquals(isHarmony() ? "Serif" : "SansSerif",
+ scValue.toString());
+ }
+ }
+
+ /**
+ * Multiple fonts are listed. The two first items refer to non-existent
+ * fonts, the last item is generic family. It is the generic family
+ * that expected to be the result of convertion.
+ */
+ public void testFontFamilyMultipleNonExistentG() {
+ attr = ss.addAttribute(empty, StyleConstants.FontFamily,
+ "NonExistentFont, UnknownFont, serif");
+
+ cssValue = attr.getAttribute(Attribute.FONT_FAMILY);
+ scValue = attr.getAttribute(StyleConstants.FontFamily);
+ assertSame(String.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertNotSame(scValue, cssValue);
+ assertFalse(scValue.equals(cssValue));
+ assertEquals("NonExistentFont, UnknownFont, serif",
+ cssValue.toString());
+ assertEquals(isHarmony() ? "Serif" : "SansSerif", scValue.toString());
+ }
+
+ /**
+ * Attribute set was added <code>CSS.Attribute.FONT_FAMILY</code>
+ * property. It is not expected to convert values to and from.
+ * <code>StyleConstants</code>.
+ */
+ public void testFontFamilyNonStyleConstants() {
+ attr = ss.addAttribute(empty, Attribute.FONT_FAMILY, "serif");
+ cssValue = attr.getAttribute(Attribute.FONT_FAMILY);
+ scValue = attr.getAttribute(StyleConstants.FontFamily);
+ assertEquals("serif", cssValue.toString());
+
+ if (isHarmony()) {
+ assertSame(String.class, scValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertEquals("Serif", scValue.toString());
+ } else {
+ assertSame(String.class, cssValue.getClass());
+ assertNull(scValue);
+ }
+ }
+
+ /**
+ * Generic family: serif.
+ */
+ public void testFontFamilySerif() {
+ attr = ss.addAttribute(empty, StyleConstants.FontFamily, "serif");
+ cssValue = attr.getAttribute(Attribute.FONT_FAMILY);
+ assertNotSame(String.class, cssValue.getClass());
+ assertEquals("serif", cssValue.toString());
+
+ scValue = attr.getAttribute(StyleConstants.FontFamily);
+ assertSame(String.class, scValue.getClass());
+ assertEquals("Serif", scValue);
+ }
+
+ /**
+ * Generic family: sans-serif.
+ */
+ public void testFontFamilySansSerif() {
+ attr = ss.addAttribute(empty, StyleConstants.FontFamily, "sans-serif");
+ cssValue = attr.getAttribute(Attribute.FONT_FAMILY);
+ assertNotSame(String.class, cssValue.getClass());
+ assertEquals("sans-serif", cssValue.toString());
+
+ scValue = attr.getAttribute(StyleConstants.FontFamily);
+ assertSame(String.class, scValue.getClass());
+ assertEquals("SansSerif", scValue);
+ }
+
+ /**
+ * Generic family: cursive.
+ * <p>Falls back to default sans-serif.
+ */
+ public void testFontFamilyCursive() {
+ attr = ss.addAttribute(empty, StyleConstants.FontFamily, "cursive");
+ cssValue = attr.getAttribute(Attribute.FONT_FAMILY);
+ assertNotSame(String.class, cssValue.getClass());
+ assertEquals("cursive", cssValue.toString());
+
+ scValue = attr.getAttribute(StyleConstants.FontFamily);
+ assertSame(String.class, scValue.getClass());
+ assertEquals("SansSerif", scValue);
+ }
+
+ /**
+ * Generic family: fantasy.
+ * <p>Falls back to default sans-serif.
+ */
+ public void testFontFamilyFantasy() {
+ attr = ss.addAttribute(empty, StyleConstants.FontFamily, "fantasy");
+ cssValue = attr.getAttribute(Attribute.FONT_FAMILY);
+ assertNotSame(String.class, cssValue.getClass());
+ assertEquals("fantasy", cssValue.toString());
+
+ scValue = attr.getAttribute(StyleConstants.FontFamily);
+ assertSame(String.class, scValue.getClass());
+ assertEquals("SansSerif", scValue);
+ }
+
+ /**
+ * Generic family: monospace.
+ */
+ public void testFontFamilyMonospace() {
+ attr = ss.addAttribute(empty, StyleConstants.FontFamily, "monospace");
+ cssValue = attr.getAttribute(Attribute.FONT_FAMILY);
+ assertNotSame(String.class, cssValue.getClass());
+ assertEquals("monospace", cssValue.toString());
+
+ scValue = attr.getAttribute(StyleConstants.FontFamily);
+ assertSame(String.class, scValue.getClass());
+ assertEquals("Monospaced", scValue);
+ }
+
+ /**
+ * Multiple fonts are listed.
+ * The first item is generic font family.
+ */
+ public void testFontFamilyGenericPlusFont() {
+ attr = ss.addAttribute(empty, StyleConstants.FontFamily,
+ "monospace, Lucida Sans");
+
+ cssValue = attr.getAttribute(Attribute.FONT_FAMILY);
+ scValue = attr.getAttribute(StyleConstants.FontFamily);
+ assertEquals("monospace, Lucida Sans", cssValue.toString());
+ assertEquals("Monospaced", scValue.toString());
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FontSizeLengthTest.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_FontSizeLengthTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FontSizeLengthTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FontSizeLengthTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,42 @@
+/*
+ * 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_FontSizeLengthTest
+ extends StyleSheet_ConvertAttr_LengthTestCase {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ cssKey = CSS.Attribute.FONT_SIZE;
+ negativeValuesInvalid = true;
+ }
+
+ 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_FontSizeTest.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_FontSizeTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FontSizeTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FontSizeTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,433 @@
+/*
+ * 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.StyleConstants;
+import javax.swing.text.html.CSS.Attribute;
+
+public class StyleSheet_ConvertAttr_FontSizeTest extends BasicSwingTestCase {
+ private static final String[] fontSizeTable = {
+ "xx-small", "x-small", "small",
+ "medium",
+ "large", "x-large", "xx-large"
+ };
+
+ private StyleSheet ss;
+ private AttributeSet empty;
+ private AttributeSet attr;
+ private Object cssValue;
+ private Object scValue;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ ss = new StyleSheet();
+ empty = ss.getEmptySet();
+ }
+
+ public void testFontSize() {
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, new Integer(10));
+
+ Enumeration names = attr.getAttributeNames();
+ Object name = names.nextElement();
+ assertSame(Attribute.FONT_SIZE, name);
+ assertFalse(names.hasMoreElements());
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertNotSame(Integer.class, cssValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertEquals(tableSizeToCSSKeyword(2), cssValue.toString());
+ assertEquals("10", scValue.toString());
+ assertEquals(10, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeXXSmall() {
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "xx-small");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertNotSame(Integer.class, cssValue.getClass());
+// assertNotSame(String.class, cssValue.getClass());
+ assertEquals("xx-small", cssValue.toString());
+ assertEquals(8, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeXSmall() {
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "x-small");
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("x-small", cssValue.toString());
+ assertEquals(10, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeSmall() {
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "small");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("small", cssValue.toString());
+ assertEquals(12, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeMedium() {
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "medium");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("medium", cssValue.toString());
+ assertEquals(14, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeLarge() {
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "large");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("large", cssValue.toString());
+ assertEquals(18, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeXLarge() {
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "x-large");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("x-large", cssValue.toString());
+ assertEquals(24, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeXXLarge() {
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "xx-large");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("xx-large", cssValue.toString());
+ assertEquals(36, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeSmaller() {
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "smaller");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("smaller", cssValue.toString());
+ assertEquals(12, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeSmallerParented() {
+ AttributeSet parent = ss.addAttribute(empty, StyleConstants.FontSize,
+ "x-large");
+ assertEquals(24, ((Integer)parent.getAttribute(StyleConstants.FontSize))
+ .intValue());
+ attr = ss.addAttribute(empty, StyleConstants.ResolveAttribute, parent);
+ attr = ss.addAttribute(attr, StyleConstants.FontSize, "smaller");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("smaller", cssValue.toString());
+ assertEquals(12, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeLarger() {
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "larger");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("larger", cssValue.toString());
+ assertEquals(12, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeLargerParented() {
+ AttributeSet parent = ss.addAttribute(empty, StyleConstants.FontSize,
+ "x-small");
+ assertEquals(10, ((Integer)parent.getAttribute(StyleConstants.FontSize))
+ .intValue());
+ attr = ss.addAttribute(empty, StyleConstants.ResolveAttribute, parent);
+ attr = ss.addAttribute(attr, StyleConstants.FontSize, "larger");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("larger", cssValue.toString());
+ assertEquals(12, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeTable() {
+ int[][] size = {
+ // {scSizeSet, cssSize, scSizeRead}
+ {6, 1, 8}, {7, 1, 8},
+ {8, 1, 8}, {9, 2, 10},
+ {10, 2, 10}, {11, 3, 12},
+ {12, 3, 12}, {13, 4, 14},
+ {14, 4, 14}, {15, 5, 18},
+ {16, 5, 18}, {17, 5, 18},
+ {18, 5, 18}, {19, 6, 24},
+ {20, 6, 24}, {21, 6, 24},
+ {22, 6, 24}, {23, 6, 24},
+ {24, 6, 24}, {25, 7, 36},
+ {26, 7, 36}, {27, 7, 36},
+ {28, 7, 36}, {29, 7, 36},
+ {30, 7, 36}, {31, 7, 36},
+ {32, 7, 36}, {33, 7, 36},
+ {34, 7, 36}, {35, 7, 36},
+ {36, 7, 36}, {37, 7, 36},
+ {38, 7, 36}, {39, 7, 36},
+ {40, 7, 36}
+ };
+ for (int i = 0; i < size.length; i++) {
+ attr = ss.addAttribute(empty, StyleConstants.FontSize,
+ new Integer(size[i][0]));
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame("@ " + i, Integer.class, scValue.getClass());
+ assertEquals("@ " + i, tableSizeToCSSKeyword(size[i][1]),
+ cssValue.toString());
+ assertEquals("@ " + i, size[i][2], ((Integer)scValue).intValue());
+ }
+ }
+
+ public void testFontSizePercentage() {
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "150%");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertNotSame(Integer.class, cssValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertEquals("150%", cssValue.toString());
+ assertEquals(12, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizePercentageParented() {
+ AttributeSet parent = ss.addAttribute(empty, StyleConstants.FontSize,
+ "large");
+ attr = ss.addAttribute(empty, StyleConstants.ResolveAttribute, parent);
+ attr = ss.addAttribute(attr, StyleConstants.FontSize, "80%");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertNotSame(Integer.class, cssValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertEquals("80%", cssValue.toString());
+ assertEquals(12, ((Integer)scValue).intValue());
+ }
+
+ /**
+ * Points, 1pt = 1/72in
+ */
+ public void testFontSizeAbsolutePt() {
+ if (!isHarmony()) {
+ return;
+ }
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "20pt");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("20pt", cssValue.toString());
+ assertEquals(20, ((Integer)scValue).intValue());
+ }
+
+ /**
+ * Pixels
+ */
+ public void testFontSizeAbsolutePx() {
+ if (!isHarmony()) {
+ return;
+ }
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "23px");
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals(29, ((Integer)scValue).intValue());
+ assertEquals("23px", cssValue.toString());
+
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "24px");
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertEquals(31, ((Integer)scValue).intValue());
+
+
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "100px");
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertEquals(130, ((Integer)scValue).intValue());
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "200px");
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertEquals(260, ((Integer)scValue).intValue());
+ }
+
+ /**
+ * Picas, 1pc = 12pt
+ */
+ public void testFontSizeAbsolutePc() {
+ if (!isHarmony()) {
+ return;
+ }
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "4pc");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("4pc", cssValue.toString());
+ assertEquals(48, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeAbsoluteMm() {
+ if (!isHarmony()) {
+ return;
+ }
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "20mm");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("20mm", cssValue.toString());
+ assertEquals(56, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeAbsoluteCm() {
+ if (!isHarmony()) {
+ return;
+ }
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "2cm");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("2cm", cssValue.toString());
+ assertEquals(56, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeRelativeEm() {
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "2em");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("2em", cssValue.toString());
+ assertEquals(12, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeRelativeEmParented() {
+ AttributeSet parent = ss.addAttribute(empty, StyleConstants.FontSize,
+ "x-large");
+ attr = ss.addAttribute(empty, StyleConstants.ResolveAttribute, parent);
+ attr = ss.addAttribute(attr, StyleConstants.FontSize, "2em");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("2em", cssValue.toString());
+ assertEquals(12, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeRelativeEx() {
+ AttributeSet parent = ss.addAttribute(empty, StyleConstants.FontSize,
+ "x-large");
+ attr = ss.addAttribute(empty, StyleConstants.ResolveAttribute, parent);
+ attr = ss.addAttribute(attr, StyleConstants.FontSize, "3ex");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("3ex", cssValue.toString());
+ assertEquals(12, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeRelativeExParented() {
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "3ex");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("3ex", cssValue.toString());
+ assertEquals(12, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeAbsoluteIn() {
+ if (!isHarmony()) {
+ return;
+ }
+
+ attr = ss.addAttribute(empty, StyleConstants.FontSize, "2in");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertEquals("2in", cssValue.toString());
+ assertEquals(144, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeAbsoluteParented() {
+ AttributeSet parent = ss.addAttribute(empty, StyleConstants.FontSize,
+ "large");
+ attr = ss.addAttribute(empty, StyleConstants.ResolveAttribute, parent);
+ attr = ss.addAttribute(attr, StyleConstants.FontSize, "80%");
+
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+ assertSame(Integer.class, scValue.getClass());
+ assertNotSame(Integer.class, cssValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertEquals("80%", cssValue.toString());
+ assertEquals(12, ((Integer)scValue).intValue());
+ }
+
+ public void testFontSizeNonStyleConstants() {
+ attr = ss.addAttribute(empty, Attribute.FONT_SIZE, "2in");
+ cssValue = attr.getAttribute(Attribute.FONT_SIZE);
+ scValue = attr.getAttribute(StyleConstants.FontSize);
+
+ if (isHarmony()) {
+ assertSame(Integer.class, scValue.getClass());
+ assertNotSame(Integer.class, cssValue.getClass());
+ assertNotSame(String.class, cssValue.getClass());
+ assertEquals(144, ((Integer)scValue).intValue());
+ } else {
+ assertSame(String.class, cssValue.getClass());
+ assertNull(scValue);
+ }
+ assertEquals("2in", cssValue.toString());
+ }
+
+ private String tableSizeToCSSKeyword(final int size) {
+ if (isHarmony()) {
+ return fontSizeTable[size - 1];
+ } else {
+ return String.valueOf(size);
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FontTest.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_FontTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FontTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FontTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,236 @@
+/*
+ * 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;
+
+public class StyleSheet_ConvertAttr_FontTest extends BasicSwingTestCase {
+ private StyleSheet ss;
+ private MutableAttributeSet simple;
+
+ private String sansSerif;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ ss = new StyleSheet();
+ simple = new SimpleAttributeSet();
+
+ sansSerif = isHarmony() ? "sans-serif" : "SansSerif";
+ }
+
+ // Invalid values
+ public void testFont01() {
+ ss.addCSSAttribute(simple, Attribute.FONT, "normal");
+ if (isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ return;
+ }
+
+ assertAttributes("normal", "normal", "normal",
+ "medium", "normal", sansSerif);
+ }
+
+ public void testFont02() {
+ ss.addCSSAttribute(simple, Attribute.FONT, "12pt");
+ if (isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ return;
+ }
+
+ assertAttributes("normal", "normal", "normal",
+ "12pt", "normal", sansSerif);
+ }
+
+ public void testFont03() {
+ ss.addCSSAttribute(simple, Attribute.FONT, "monospace");
+ if (isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ return;
+ }
+
+ assertAttributes("normal", "normal", "normal",
+ /*size*/ "monospace", "normal", /*family*/ sansSerif);
+ }
+
+
+ // Valid values
+ public void testFont05() {
+ ss.addCSSAttribute(simple, Attribute.FONT, "small serif");
+ assertAttributes("normal", "normal", "normal",
+ "small", "normal", "serif");
+ }
+
+ public void testFont06() {
+ ss.addCSSAttribute(simple, Attribute.FONT, "italic small serif");
+ assertAttributes("italic", "normal", "normal",
+ "small", "normal", "serif");
+ }
+
+ public void testFont07() {
+ ss.addCSSAttribute(simple, Attribute.FONT, "italic bold small serif");
+ assertAttributes("italic", "normal", "bold",
+ "small", "normal", "serif");
+ }
+
+ public void testFont08() {
+ ss.addCSSAttribute(simple, Attribute.FONT, "bold italic small serif");
+ assertAttributes("italic", "normal", "bold",
+ "small", "normal", "serif");
+ }
+
+ public void testFont09() {
+ ss.addCSSAttribute(simple, Attribute.FONT,
+ "bold small-caps italic small serif");
+ assertAttributes("italic", "small-caps", "bold",
+ "small", "normal", "serif");
+ }
+
+ public void testFont10() {
+ ss.addCSSAttribute(simple, Attribute.FONT,
+ "bold normal small-caps italic small serif");
+ if (isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ return;
+ }
+ assertAttributes("normal", "small-caps", "bold",
+ /*size*/ "italic", "normal", "small serif");
+ }
+
+ public void testFont11() {
+ ss.addCSSAttribute(simple, Attribute.FONT,
+ "bold small-caps italic normal small serif");
+ if (isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ return;
+ }
+ assertAttributes("italic", "small-caps", "bold",
+ /*size*/ "normal", "normal", "small serif");
+ }
+
+ public void testFont12() {
+ ss.addCSSAttribute(simple, Attribute.FONT,
+ "bold italic large 'Times New Roman', Garamond, serif");
+ assertAttributes("italic", "normal", "bold",
+ "large", "normal",
+ "'Times New Roman', Garamond, serif");
+ }
+
+ public void testFont13() {
+ ss.addCSSAttribute(simple, Attribute.FONT,
+ "larger/1.2 Arial, Verdana, sans-serif");
+ assertAttributes("normal", "normal", "normal",
+ "larger", "1.2", "Arial, Verdana, sans-serif");
+ }
+
+ public void testFont14() {
+ ss.addCSSAttribute(simple, Attribute.FONT,
+ "100% / 110% \"Courier New\", \"Lucida Console\", "
+ + "monospace");
+ assertAttributes("normal", "normal", "normal",
+ "100%", "110%",
+ "\"Courier New\", \"Lucida Console\", monospace");
+ }
+
+ public void testFont15() {
+ ss.addCSSAttribute(simple, Attribute.FONT, "smaller /120% fantasy");
+ assertAttributes("normal", "normal", "normal",
+ "smaller", "120%", "fantasy");
+ }
+
+ public void testFont16() {
+ ss.addCSSAttribute(simple, Attribute.FONT, "small/ 120% cursive");
+ assertAttributes("normal", "normal", "normal",
+ "small", "120%", "cursive");
+ }
+
+ public void testFont17() {
+ ss.addCSSAttribute(simple, Attribute.FONT, "x-small/ /18pt sans-serif");
+ if (isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ return;
+ }
+
+ assertAttributes("normal", "normal", "normal",
+ "x-small", "/18pt", "sans-serif");
+ }
+
+ public void testFont18() {
+ ss.addCSSAttribute(simple, Attribute.FONT, "14/ 18pt sans-serif");
+ if (isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ return;
+ }
+
+ assertAttributes("normal", "normal", "normal",
+ "14", "18pt", "sans-serif");
+ }
+
+ public void testFont19() {
+ ss.addCSSAttribute(simple, Attribute.FONT, "14pt/");
+ if (isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ return;
+ }
+
+ assertAttributes("normal", "normal", "normal",
+ "14pt", "normal", "SansSerif");
+ }
+
+ public void testFont20() {
+ ss.addCSSAttribute(simple, Attribute.FONT, "14pt /");
+ if (isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ return;
+ }
+
+ assertAttributes("normal", "normal", "normal",
+ "14pt", "normal", "SansSerif");
+ }
+
+ private void assertAttributes(final String style,
+ final String variant,
+ final String weight,
+ final String size,
+ final String lineHeight,
+ final String family) {
+ assertEquals("Attribute count", 6, simple.getAttributeCount());
+
+ assertEquals("font-style",
+ style, getCSSAttribute(Attribute.FONT_STYLE));
+ assertEquals("font-variant",
+ variant, getCSSAttribute(Attribute.FONT_VARIANT));
+ assertEquals("font-weight",
+ weight, getCSSAttribute(Attribute.FONT_WEIGHT));
+ assertEquals("font-size",
+ size, getCSSAttribute(Attribute.FONT_SIZE));
+ assertEquals("line-height",
+ lineHeight, getCSSAttribute(Attribute.LINE_HEIGHT));
+ assertEquals("font-family",
+ family, getCSSAttribute(Attribute.FONT_FAMILY));
+ }
+
+ private String getCSSAttribute(final Attribute cssKey) {
+ final Object result = simple.getAttribute(cssKey);
+ return result != null ? result.toString() : null;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FontVariantTest.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_FontVariantTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FontVariantTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_FontVariantTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,62 @@
+/*
+ * 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_FontVariantTest 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 testFontVariantNormal() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.FONT_VARIANT, "normal");
+ cssValue = simple.getAttribute(Attribute.FONT_VARIANT);
+ assertEquals("normal", cssValue.toString());
+ }
+
+ public void testFontVariantSmallCaps() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.FONT_VARIANT, "small-caps");
+ cssValue = simple.getAttribute(Attribute.FONT_VARIANT);
+ assertEquals("small-caps", cssValue.toString());
+ }
+
+ public void testFontVariantInvalid() throws Exception {
+ ss.addCSSAttribute(simple, Attribute.FONT_VARIANT, "invalid");
+ if (BasicSwingTestCase.isHarmony()) {
+ assertEquals(0, simple.getAttributeCount());
+ assertNull(simple.getAttribute(Attribute.FONT_VARIANT));
+ return;
+ }
+ cssValue = simple.getAttribute(Attribute.FONT_VARIANT);
+ assertEquals("invalid", cssValue.toString());
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_HeightTest.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_HeightTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_HeightTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/StyleSheet_ConvertAttr_HeightTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,47 @@
+/*
+ * 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_HeightTest
+ extends StyleSheet_ConvertAttr_WidthTest {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ cssKey = CSS.Attribute.HEIGHT;
+ percentageValuesInvalid = true;
+ }
+
+ public void testLength11_1Percent() {
+ percentageValuesInvalid = BasicSwingTestCase.isHarmony();
+ super.testLength11_1Percent();
+ }
+
+ public void testLengthPlus11_1Percent() {
+ percentageValuesInvalid = BasicSwingTestCase.isHarmony();
+ super.testLengthPlus11_1Percent();
+ }
+
+ public void testLengthMinus11_1Percent() {
+ percentageValuesInvalid = BasicSwingTestCase.isHarmony();
+ super.testLengthMinus11_1Percent();
+ }
+}
|