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: public class StyleSheet_ConvertAttr_BoldTest extends BasicSwingTestCase {
032: private StyleSheet ss;
033: private AttributeSet empty;
034: private AttributeSet attr;
035: private MutableAttributeSet simple;
036: private Object cssValue;
037: private Object scValue;
038:
039: protected void setUp() throws Exception {
040: super .setUp();
041: ss = new StyleSheet();
042: empty = ss.getEmptySet();
043: simple = new SimpleAttributeSet();
044: }
045:
046: public void testBold() {
047: attr = ss
048: .addAttribute(empty, StyleConstants.Bold, Boolean.TRUE);
049:
050: Enumeration names = attr.getAttributeNames();
051: Object name = names.nextElement();
052: assertSame(Attribute.FONT_WEIGHT, name);
053: assertFalse(names.hasMoreElements());
054:
055: cssValue = attr.getAttribute(Attribute.FONT_WEIGHT);
056: scValue = attr.getAttribute(StyleConstants.Bold);
057: assertSame(Boolean.class, scValue.getClass());
058: assertNotSame(Boolean.class, cssValue.getClass());
059: assertNotSame(String.class, cssValue.getClass());
060: assertEquals("bold", cssValue.toString());
061: assertEquals("true", scValue.toString());
062: assertTrue(((Boolean) scValue).booleanValue());
063: }
064:
065: public void testBoldFalse() {
066: attr = ss.addAttribute(empty, StyleConstants.Bold,
067: Boolean.FALSE);
068:
069: Enumeration names = attr.getAttributeNames();
070: Object name = names.nextElement();
071: assertSame(Attribute.FONT_WEIGHT, name);
072: assertFalse(names.hasMoreElements());
073:
074: cssValue = attr.getAttribute(Attribute.FONT_WEIGHT);
075: scValue = attr.getAttribute(StyleConstants.Bold);
076: assertSame(Boolean.class, scValue.getClass());
077: assertNotSame(Boolean.class, cssValue.getClass());
078: assertNotSame(String.class, cssValue.getClass());
079: assertEquals("normal", cssValue.toString());
080: assertFalse(((Boolean) scValue).booleanValue());
081: }
082:
083: public void testBoldBold() throws Exception {
084: ss.addCSSAttribute(simple, Attribute.FONT_WEIGHT, "bold");
085: assertEquals(1, simple.getAttributeCount());
086: cssValue = simple.getAttribute(Attribute.FONT_WEIGHT);
087: assertEquals("bold", cssValue.toString());
088:
089: attr = ss.createSmallAttributeSet(simple);
090: scValue = attr.getAttribute(StyleConstants.Bold);
091: assertNotNull(scValue);
092: assertTrue(((Boolean) scValue).booleanValue());
093: }
094:
095: public void testBoldNormal() throws Exception {
096: ss.addCSSAttribute(simple, Attribute.FONT_WEIGHT, "normal");
097: assertEquals(1, simple.getAttributeCount());
098: cssValue = simple.getAttribute(Attribute.FONT_WEIGHT);
099: assertEquals("normal", cssValue.toString());
100:
101: attr = ss.createSmallAttributeSet(simple);
102: scValue = attr.getAttribute(StyleConstants.Bold);
103: assertNotNull(scValue);
104: assertFalse(((Boolean) scValue).booleanValue());
105: }
106:
107: public void testBoldBolder() throws Exception {
108: ss.addCSSAttribute(simple, Attribute.FONT_WEIGHT, "bolder");
109: assertEquals(1, simple.getAttributeCount());
110: cssValue = simple.getAttribute(Attribute.FONT_WEIGHT);
111: if (isHarmony()) {
112: assertEquals("bolder", cssValue.toString());
113:
114: attr = ss.createSmallAttributeSet(simple);
115: scValue = attr.getAttribute(StyleConstants.Bold);
116: assertNotNull(scValue);
117: assertTrue(((Boolean) scValue).booleanValue());
118: } else {
119: assertEquals("normal", cssValue.toString()); // default value
120: }
121: }
122:
123: public void testBoldLighter() throws Exception {
124: ss.addCSSAttribute(simple, Attribute.FONT_WEIGHT, "lighter");
125: assertEquals(1, simple.getAttributeCount());
126: cssValue = simple.getAttribute(Attribute.FONT_WEIGHT);
127: if (isHarmony()) {
128: assertEquals("lighter", cssValue.toString());
129:
130: attr = ss.createSmallAttributeSet(simple);
131: scValue = attr.getAttribute(StyleConstants.Bold);
132: assertNotNull(scValue);
133: assertFalse(((Boolean) scValue).booleanValue());
134: } else {
135: assertEquals("normal", cssValue.toString()); // default value
136: }
137: }
138:
139: public void testBold100() throws Exception {
140: ss.addCSSAttribute(simple, Attribute.FONT_WEIGHT, "100");
141: assertEquals(1, simple.getAttributeCount());
142: cssValue = simple.getAttribute(Attribute.FONT_WEIGHT);
143: assertEquals("100", cssValue.toString());
144:
145: attr = ss.createSmallAttributeSet(simple);
146: scValue = attr.getAttribute(StyleConstants.Bold);
147: assertNotNull(scValue);
148: assertFalse(((Boolean) scValue).booleanValue());
149: }
150:
151: public void testBold200() throws Exception {
152: ss.addCSSAttribute(simple, Attribute.FONT_WEIGHT, "200");
153: assertEquals(1, simple.getAttributeCount());
154: cssValue = simple.getAttribute(Attribute.FONT_WEIGHT);
155: assertEquals("200", cssValue.toString());
156:
157: attr = ss.createSmallAttributeSet(simple);
158: scValue = attr.getAttribute(StyleConstants.Bold);
159: assertNotNull(scValue);
160: assertFalse(((Boolean) scValue).booleanValue());
161: }
162:
163: public void testBold300() throws Exception {
164: ss.addCSSAttribute(simple, Attribute.FONT_WEIGHT, "300");
165: assertEquals(1, simple.getAttributeCount());
166: cssValue = simple.getAttribute(Attribute.FONT_WEIGHT);
167: assertEquals("300", cssValue.toString());
168:
169: attr = ss.createSmallAttributeSet(simple);
170: scValue = attr.getAttribute(StyleConstants.Bold);
171: assertNotNull(scValue);
172: assertFalse(((Boolean) scValue).booleanValue());
173: }
174:
175: public void testBold400() throws Exception {
176: ss.addCSSAttribute(simple, Attribute.FONT_WEIGHT, "400");
177: assertEquals(1, simple.getAttributeCount());
178: cssValue = simple.getAttribute(Attribute.FONT_WEIGHT);
179: assertEquals("400", cssValue.toString());
180:
181: attr = ss.createSmallAttributeSet(simple);
182: scValue = attr.getAttribute(StyleConstants.Bold);
183: assertNotNull(scValue);
184: assertFalse(((Boolean) scValue).booleanValue());
185: }
186:
187: public void testBold500() throws Exception {
188: ss.addCSSAttribute(simple, Attribute.FONT_WEIGHT, "500");
189: assertEquals(1, simple.getAttributeCount());
190: cssValue = simple.getAttribute(Attribute.FONT_WEIGHT);
191: assertEquals("500", cssValue.toString());
192:
193: attr = ss.createSmallAttributeSet(simple);
194: scValue = attr.getAttribute(StyleConstants.Bold);
195: assertNotNull(scValue);
196: assertFalse(((Boolean) scValue).booleanValue());
197: }
198:
199: public void testBold600() throws Exception {
200: ss.addCSSAttribute(simple, Attribute.FONT_WEIGHT, "600");
201: assertEquals(1, simple.getAttributeCount());
202: cssValue = simple.getAttribute(Attribute.FONT_WEIGHT);
203: assertEquals("600", cssValue.toString());
204:
205: attr = ss.createSmallAttributeSet(simple);
206: scValue = attr.getAttribute(StyleConstants.Bold);
207: assertNotNull(scValue);
208: assertTrue(((Boolean) scValue).booleanValue());
209: }
210:
211: public void testBold700() throws Exception {
212: ss.addCSSAttribute(simple, Attribute.FONT_WEIGHT, "700");
213: assertEquals(1, simple.getAttributeCount());
214: cssValue = simple.getAttribute(Attribute.FONT_WEIGHT);
215: assertEquals("700", cssValue.toString());
216:
217: attr = ss.createSmallAttributeSet(simple);
218: scValue = attr.getAttribute(StyleConstants.Bold);
219: assertNotNull(scValue);
220: assertTrue(((Boolean) scValue).booleanValue());
221: }
222:
223: public void testBold800() throws Exception {
224: ss.addCSSAttribute(simple, Attribute.FONT_WEIGHT, "800");
225: assertEquals(1, simple.getAttributeCount());
226: cssValue = simple.getAttribute(Attribute.FONT_WEIGHT);
227: assertEquals("800", cssValue.toString());
228:
229: attr = ss.createSmallAttributeSet(simple);
230: scValue = attr.getAttribute(StyleConstants.Bold);
231: assertNotNull(scValue);
232: assertTrue(((Boolean) scValue).booleanValue());
233: }
234:
235: public void testBold900() throws Exception {
236: ss.addCSSAttribute(simple, Attribute.FONT_WEIGHT, "900");
237: assertEquals(1, simple.getAttributeCount());
238: cssValue = simple.getAttribute(Attribute.FONT_WEIGHT);
239: assertEquals("900", cssValue.toString());
240:
241: attr = ss.createSmallAttributeSet(simple);
242: scValue = attr.getAttribute(StyleConstants.Bold);
243: assertNotNull(scValue);
244: assertTrue(((Boolean) scValue).booleanValue());
245: }
246: }
|