001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Alexey A. Ivanov
019: * @version $Revision$
020: */package javax.swing.text.html;
021:
022: import java.util.Enumeration;
023:
024: import javax.swing.BasicSwingTestCase;
025: import javax.swing.text.AttributeSet;
026: import javax.swing.text.MutableAttributeSet;
027: import javax.swing.text.SimpleAttributeSet;
028: import javax.swing.text.StyleConstants;
029: import javax.swing.text.html.CSS.Attribute;
030:
031: import junit.framework.TestCase;
032:
033: public class StyleSheet_ConvertAttr_ItalicTest extends TestCase {
034: private StyleSheet ss;
035: private AttributeSet empty;
036: private AttributeSet attr;
037: private MutableAttributeSet simple;
038: private Object cssValue;
039: private Object scValue;
040:
041: protected void setUp() throws Exception {
042: super .setUp();
043: ss = new StyleSheet();
044: empty = ss.getEmptySet();
045: simple = new SimpleAttributeSet();
046: }
047:
048: public void testItalic() {
049: attr = ss.addAttribute(empty, StyleConstants.Italic,
050: Boolean.TRUE);
051:
052: Enumeration names = attr.getAttributeNames();
053: Object name = names.nextElement();
054: assertSame(Attribute.FONT_STYLE, name);
055: assertFalse(names.hasMoreElements());
056:
057: cssValue = attr.getAttribute(Attribute.FONT_STYLE);
058: scValue = attr.getAttribute(StyleConstants.Italic);
059: assertSame(Boolean.class, scValue.getClass());
060: assertNotSame(Boolean.class, cssValue.getClass());
061: assertNotSame(String.class, cssValue.getClass());
062: assertEquals("italic", cssValue.toString());
063: assertEquals("true", scValue.toString());
064: assertTrue(((Boolean) scValue).booleanValue());
065: }
066:
067: public void testItalicFalse() {
068: attr = ss.addAttribute(empty, StyleConstants.Italic,
069: Boolean.FALSE);
070:
071: Enumeration names = attr.getAttributeNames();
072: Object name = names.nextElement();
073: assertSame(Attribute.FONT_STYLE, name);
074: assertFalse(names.hasMoreElements());
075:
076: cssValue = attr.getAttribute(Attribute.FONT_STYLE);
077: scValue = attr.getAttribute(StyleConstants.Italic);
078: assertSame(Boolean.class, scValue.getClass());
079: assertNotSame(Boolean.class, cssValue.getClass());
080: assertNotSame(String.class, cssValue.getClass());
081: assertEquals(BasicSwingTestCase.isHarmony() ? "normal" : "",
082: cssValue.toString());
083: assertFalse(((Boolean) scValue).booleanValue());
084: }
085:
086: public void testItalicItalic() throws Exception {
087: ss.addCSSAttribute(simple, Attribute.FONT_STYLE, "italic");
088: assertEquals(1, simple.getAttributeCount());
089: cssValue = simple.getAttribute(Attribute.FONT_STYLE);
090: assertEquals("italic", cssValue.toString());
091:
092: attr = ss.createSmallAttributeSet(simple);
093: scValue = attr.getAttribute(StyleConstants.Italic);
094: assertNotNull(scValue);
095: assertTrue(((Boolean) scValue).booleanValue());
096: }
097:
098: public void testItalicNormal() throws Exception {
099: ss.addCSSAttribute(simple, Attribute.FONT_STYLE, "normal");
100: assertEquals(1, simple.getAttributeCount());
101: cssValue = simple.getAttribute(Attribute.FONT_STYLE);
102: assertEquals("normal", cssValue.toString());
103:
104: attr = ss.createSmallAttributeSet(simple);
105: scValue = attr.getAttribute(StyleConstants.Italic);
106: assertNotNull(scValue);
107: assertFalse(((Boolean) scValue).booleanValue());
108: }
109:
110: public void testItalicOblique() throws Exception {
111: ss.addCSSAttribute(simple, Attribute.FONT_STYLE, "oblique");
112: assertEquals(1, simple.getAttributeCount());
113: cssValue = simple.getAttribute(Attribute.FONT_STYLE);
114: assertEquals("oblique", cssValue.toString());
115:
116: attr = ss.createSmallAttributeSet(simple);
117: scValue = attr.getAttribute(StyleConstants.Italic);
118: assertNotNull(scValue);
119: assertFalse(((Boolean) scValue).booleanValue());
120: }
121:
122: public void testItalicInvalidValue() throws Exception {
123: ss.addCSSAttribute(simple, Attribute.FONT_STYLE, "invalid");
124: cssValue = simple.getAttribute(Attribute.FONT_STYLE);
125: if (BasicSwingTestCase.isHarmony()) {
126: assertEquals(0, simple.getAttributeCount());
127: assertNull(cssValue);
128: return;
129: }
130:
131: assertEquals(1, simple.getAttributeCount());
132: assertEquals("invalid", cssValue.toString());
133:
134: attr = ss.createSmallAttributeSet(simple);
135: scValue = attr.getAttribute(StyleConstants.Italic);
136: assertNotNull(scValue);
137: assertFalse(((Boolean) scValue).booleanValue());
138: }
139: }
|