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: /**
032: * Tests <code>SmallAttributeSet</code> returned by
033: * <code>StyleSheet.addAttribute</code> method. The returned attribute set
034: * contains <code>CSS.Attribute</code>. It converts the value to
035: * <code>StyleConstants</code> when a <code>StyleConstants</code> attribute
036: * is requested.
037: * <p>
038: * The attribute used for testing is <code>StyleConstants.Bold</code>.
039: * It corresponds to <code>Attribute.FONT_WEIGHT</code>.
040: *
041: * @see StyleSheet
042: * @see StyleSheet#addAttribute(Object, Object)
043: * @see StyleSheet#createSmallAttributeSet(AttributeSet)
044: * @see CSS.Attribute
045: * @see javax.swing.text.StyleContext.SmallAttributeSet
046: */
047: public class StyleSheet_Small_Test extends BasicSwingTestCase {
048: private static final Object scAttribute = StyleConstants.Bold;
049: private static final Object scValue = Boolean.TRUE;
050: private static final Object cssAttribute = Attribute.FONT_WEIGHT;
051:
052: private StyleSheet ss;
053: private AttributeSet empty;
054: private AttributeSet attr;
055:
056: protected void setUp() throws Exception {
057: super .setUp();
058: ss = new StyleSheet();
059: empty = ss.getEmptySet();
060:
061: attr = ss.addAttribute(empty, scAttribute, scValue);
062: }
063:
064: public void testGetAttribute() throws Exception {
065: Object value = attr.getAttribute(cssAttribute);
066: assertNotSame(Boolean.class, value.getClass());
067: assertNotSame(String.class, value.getClass());
068: assertEquals("bold", value.toString());
069:
070: value = attr.getAttribute(scAttribute);
071: assertSame(Boolean.class, value.getClass());
072: assertTrue(((Boolean) value).booleanValue());
073: assertSame(scValue, value);
074: }
075:
076: public void testIsDefined() throws Exception {
077: assertTrue(attr.isDefined(scAttribute));
078: assertTrue(attr.isDefined(cssAttribute));
079: }
080:
081: public void testGetNames() throws Exception {
082: final Enumeration keys = attr.getAttributeNames();
083: final Object key = keys.nextElement();
084: assertSame(cssAttribute, key);
085: assertFalse(keys.hasMoreElements());
086: }
087:
088: public void testGetAttributeCount() throws Exception {
089: assertEquals(1, attr.getAttributeCount());
090: }
091:
092: public void testIsEqualSame() throws Exception {
093: assertTrue(attr.isEqual(attr));
094:
095: final MutableAttributeSet simple = new SimpleAttributeSet(attr);
096: assertTrue(attr.isEqual(simple));
097: assertTrue(simple.isEqual(attr));
098: }
099:
100: public void testIsEqualMutable() throws Exception {
101: final MutableAttributeSet simple = new SimpleAttributeSet();
102: simple.addAttribute(scAttribute, scValue);
103:
104: assertTrue(attr.isEqual(simple));
105: if (isHarmony()) {
106: assertTrue(simple.isEqual(attr));
107: } else {
108: assertFalse(simple.isEqual(attr));
109: }
110: }
111:
112: public void testCopyAttributes() throws Exception {
113: assertSame(attr, attr.copyAttributes());
114: }
115:
116: public void testContainsAttribute() throws Exception {
117: assertTrue(attr.containsAttribute(cssAttribute, attr
118: .getAttribute(cssAttribute)));
119: assertTrue(attr.containsAttribute(scAttribute, scValue));
120: }
121:
122: public void testContainsAttributeAnother() throws Exception {
123: final AttributeSet another = ss.addAttribute(empty,
124: scAttribute, scValue);
125:
126: assertEquals(attr.getAttribute(cssAttribute).toString(),
127: another.getAttribute(cssAttribute).toString());
128: if (isHarmony()) {
129: assertTrue(attr.containsAttribute(cssAttribute, another
130: .getAttribute(cssAttribute)));
131: } else {
132: assertFalse(attr.containsAttribute(cssAttribute, another
133: .getAttribute(cssAttribute)));
134: }
135: }
136:
137: public void testContainsAttributesSame() throws Exception {
138: assertTrue(attr.containsAttributes(attr));
139:
140: final MutableAttributeSet simple = new SimpleAttributeSet(attr);
141:
142: assertTrue(attr.containsAttributes(simple));
143: assertTrue(simple.containsAttributes(attr));
144: }
145:
146: public void testContainsAttributesMutable() throws Exception {
147: final MutableAttributeSet simple = new SimpleAttributeSet();
148: simple.addAttribute(scAttribute, scValue);
149:
150: assertTrue(attr.containsAttributes(simple));
151: assertFalse(simple.containsAttributes(attr));
152: }
153:
154: public void testContainsAttributesSmall() throws Exception {
155: final AttributeSet another = ss.addAttribute(empty,
156: scAttribute, scValue);
157:
158: if (isHarmony()) {
159: assertTrue(attr.containsAttributes(another));
160: assertTrue(another.containsAttributes(attr));
161: } else {
162: assertFalse(attr.containsAttributes(another));
163: assertFalse(another.containsAttributes(attr));
164: }
165: }
166: }
|