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_TextAlignTest extends
032: BasicSwingTestCase {
033: private StyleSheet ss;
034: private AttributeSet empty;
035: private AttributeSet attr;
036: private MutableAttributeSet simple;
037: private Object cssValue;
038: private Object scValue;
039:
040: protected void setUp() throws Exception {
041: super .setUp();
042: ss = new StyleSheet();
043: empty = ss.getEmptySet();
044: simple = new SimpleAttributeSet();
045: }
046:
047: public void testTextAlign() {
048: attr = ss.addAttribute(empty, StyleConstants.Alignment,
049: new Integer(StyleConstants.ALIGN_RIGHT));
050:
051: Enumeration names = attr.getAttributeNames();
052: Object name = names.nextElement();
053: assertSame(Attribute.TEXT_ALIGN, name);
054: assertFalse(names.hasMoreElements());
055:
056: cssValue = attr.getAttribute(Attribute.TEXT_ALIGN);
057: scValue = attr.getAttribute(StyleConstants.Alignment);
058: assertSame(Integer.class, scValue.getClass());
059: assertNotSame(Integer.class, cssValue.getClass());
060: assertNotSame(String.class, cssValue.getClass());
061: }
062:
063: public void testTextAlignInvalid() {
064: attr = ss.addAttribute(empty, StyleConstants.Alignment,
065: new Integer(100));
066:
067: Enumeration names = attr.getAttributeNames();
068: Object name = names.nextElement();
069: assertSame(Attribute.TEXT_ALIGN, name);
070: assertFalse(names.hasMoreElements());
071:
072: cssValue = attr.getAttribute(Attribute.TEXT_ALIGN);
073: scValue = attr.getAttribute(StyleConstants.Alignment);
074: assertSame(Integer.class, scValue.getClass());
075: assertNotSame(Integer.class, cssValue.getClass());
076: assertNotSame(String.class, cssValue.getClass());
077: assertEquals("left", cssValue.toString());
078: assertEquals(StyleConstants.ALIGN_LEFT, ((Integer) scValue)
079: .intValue());
080: }
081:
082: public void testTextAlignLeft() {
083: attr = ss.addAttribute(empty, StyleConstants.Alignment,
084: new Integer(StyleConstants.ALIGN_LEFT));
085:
086: cssValue = attr.getAttribute(Attribute.TEXT_ALIGN);
087: scValue = attr.getAttribute(StyleConstants.Alignment);
088: assertEquals("left", cssValue.toString());
089: assertEquals(StyleConstants.ALIGN_LEFT, ((Integer) scValue)
090: .intValue());
091: }
092:
093: public void testTextAlignCenter() {
094: attr = ss.addAttribute(empty, StyleConstants.Alignment,
095: new Integer(StyleConstants.ALIGN_CENTER));
096:
097: cssValue = attr.getAttribute(Attribute.TEXT_ALIGN);
098: scValue = attr.getAttribute(StyleConstants.Alignment);
099: assertEquals("center", cssValue.toString());
100: assertEquals(StyleConstants.ALIGN_CENTER, ((Integer) scValue)
101: .intValue());
102: }
103:
104: public void testTextAlignRight() {
105: attr = ss.addAttribute(empty, StyleConstants.Alignment,
106: new Integer(StyleConstants.ALIGN_RIGHT));
107:
108: cssValue = attr.getAttribute(Attribute.TEXT_ALIGN);
109: scValue = attr.getAttribute(StyleConstants.Alignment);
110: assertEquals("right", cssValue.toString());
111: assertEquals(StyleConstants.ALIGN_RIGHT, ((Integer) scValue)
112: .intValue());
113: }
114:
115: public void testTextAlignJustify() {
116: attr = ss.addAttribute(empty, StyleConstants.Alignment,
117: new Integer(StyleConstants.ALIGN_JUSTIFIED));
118:
119: cssValue = attr.getAttribute(Attribute.TEXT_ALIGN);
120: scValue = attr.getAttribute(StyleConstants.Alignment);
121: assertEquals("justify", cssValue.toString());
122: assertEquals(StyleConstants.ALIGN_JUSTIFIED,
123: ((Integer) scValue).intValue());
124: }
125:
126: public void testTextAlignStringLeft() {
127: ss.addCSSAttribute(simple, Attribute.TEXT_ALIGN, "left");
128: attr = ss.createSmallAttributeSet(simple);
129:
130: cssValue = attr.getAttribute(Attribute.TEXT_ALIGN);
131: scValue = attr.getAttribute(StyleConstants.Alignment);
132: assertEquals("left", cssValue.toString());
133: assertEquals(StyleConstants.ALIGN_LEFT, ((Integer) scValue)
134: .intValue());
135: }
136:
137: public void testTextAlignStringCenter() {
138: ss.addCSSAttribute(simple, Attribute.TEXT_ALIGN, "center");
139: attr = ss.createSmallAttributeSet(simple);
140:
141: cssValue = attr.getAttribute(Attribute.TEXT_ALIGN);
142: scValue = attr.getAttribute(StyleConstants.Alignment);
143: assertEquals("center", cssValue.toString());
144: assertEquals(StyleConstants.ALIGN_CENTER, ((Integer) scValue)
145: .intValue());
146: }
147:
148: public void testTextAlignStringRight() {
149: ss.addCSSAttribute(simple, Attribute.TEXT_ALIGN, "right");
150: attr = ss.createSmallAttributeSet(simple);
151:
152: cssValue = attr.getAttribute(Attribute.TEXT_ALIGN);
153: scValue = attr.getAttribute(StyleConstants.Alignment);
154: assertEquals("right", cssValue.toString());
155: assertEquals(StyleConstants.ALIGN_RIGHT, ((Integer) scValue)
156: .intValue());
157: }
158:
159: public void testTextAlignStringJustify() {
160: ss.addCSSAttribute(simple, Attribute.TEXT_ALIGN, "justify");
161: attr = ss.createSmallAttributeSet(simple);
162:
163: cssValue = attr.getAttribute(Attribute.TEXT_ALIGN);
164: scValue = attr.getAttribute(StyleConstants.Alignment);
165: assertEquals("justify", cssValue.toString());
166: assertEquals(StyleConstants.ALIGN_JUSTIFIED,
167: ((Integer) scValue).intValue());
168: }
169:
170: public void testTextAlignStringJustified() {
171: assertEquals(0, simple.getAttributeCount());
172: ss.addCSSAttribute(simple, Attribute.TEXT_ALIGN, "justified");
173: if (isHarmony()) {
174: assertEquals(0, simple.getAttributeCount());
175: return;
176: }
177:
178: attr = ss.createSmallAttributeSet(simple);
179: cssValue = attr.getAttribute(Attribute.TEXT_ALIGN);
180: scValue = attr.getAttribute(StyleConstants.Alignment);
181: assertEquals("justified", cssValue.toString());
182: assertEquals(StyleConstants.ALIGN_LEFT, ((Integer) scValue)
183: .intValue());
184: }
185:
186: public void testTextAlignStringInvalid() {
187: assertEquals(0, simple.getAttributeCount());
188: ss.addCSSAttribute(simple, Attribute.TEXT_ALIGN, "super-align");
189: if (isHarmony()) {
190: assertEquals(0, simple.getAttributeCount());
191: return;
192: }
193:
194: attr = ss.createSmallAttributeSet(simple);
195: cssValue = attr.getAttribute(Attribute.TEXT_ALIGN);
196: scValue = attr.getAttribute(StyleConstants.Alignment);
197: assertEquals("super-align", cssValue.toString());
198: assertEquals(StyleConstants.ALIGN_LEFT, ((Integer) scValue)
199: .intValue());
200: }
201: }
|