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.io.IOException;
023:
024: import javax.swing.BasicSwingTestCase;
025: import javax.swing.text.StyleContext;
026: import javax.swing.text.html.CSS.Attribute;
027:
028: public class CSSTest extends BasicSwingTestCase {
029: public void testGetAllAttributeKeys() {
030: Attribute[] keys = CSS.getAllAttributeKeys();
031: if (isHarmony()) {
032: // The array contains only the public attribute keys
033: assertEquals(53, keys.length);
034: } else {
035: // The array contains two more attributes than declared in the Spec
036: assertEquals(55, keys.length);
037: }
038: Attribute[] allAttributeKeys = { Attribute.BACKGROUND,
039: Attribute.BACKGROUND_ATTACHMENT,
040: Attribute.BACKGROUND_COLOR, Attribute.BACKGROUND_IMAGE,
041: Attribute.BACKGROUND_POSITION,
042: Attribute.BACKGROUND_REPEAT, Attribute.BORDER,
043: Attribute.BORDER_BOTTOM, Attribute.BORDER_BOTTOM_WIDTH,
044: Attribute.BORDER_COLOR, Attribute.BORDER_LEFT,
045: Attribute.BORDER_LEFT_WIDTH, Attribute.BORDER_RIGHT,
046: Attribute.BORDER_RIGHT_WIDTH, Attribute.BORDER_STYLE,
047: Attribute.BORDER_TOP, Attribute.BORDER_TOP_WIDTH,
048: Attribute.BORDER_WIDTH, Attribute.CLEAR,
049: Attribute.COLOR, Attribute.DISPLAY, Attribute.FLOAT,
050: Attribute.FONT, Attribute.FONT_FAMILY,
051: Attribute.FONT_SIZE, Attribute.FONT_STYLE,
052: Attribute.FONT_VARIANT, Attribute.FONT_WEIGHT,
053: Attribute.HEIGHT, Attribute.LETTER_SPACING,
054: Attribute.LINE_HEIGHT, Attribute.LIST_STYLE,
055: Attribute.LIST_STYLE_IMAGE,
056: Attribute.LIST_STYLE_POSITION,
057: Attribute.LIST_STYLE_TYPE, Attribute.MARGIN,
058: Attribute.MARGIN_BOTTOM, Attribute.MARGIN_LEFT,
059: Attribute.MARGIN_RIGHT, Attribute.MARGIN_TOP,
060: Attribute.PADDING, Attribute.PADDING_BOTTOM,
061: Attribute.PADDING_LEFT, Attribute.PADDING_RIGHT,
062: Attribute.PADDING_TOP, Attribute.TEXT_ALIGN,
063: Attribute.TEXT_DECORATION, Attribute.TEXT_INDENT,
064: Attribute.TEXT_TRANSFORM, Attribute.VERTICAL_ALIGN,
065: Attribute.WHITE_SPACE, Attribute.WIDTH,
066: Attribute.WORD_SPACING };
067: final boolean[] found = new boolean[allAttributeKeys.length];
068:
069: for (int i = 0; i < allAttributeKeys.length; i++) {
070: for (int j = 0; j < allAttributeKeys.length; j++) {
071: if (allAttributeKeys[i] == keys[j]) {
072: found[i] = true;
073: break;
074: }
075: }
076: }
077:
078: for (int i = 0; i < found.length; i++) {
079: assertTrue("Attribute " + allAttributeKeys[i]
080: + " was not found", found[i]);
081: }
082: }
083:
084: public void testGetAttribute() throws Exception {
085: // These properties are defined only in CSS Level 2
086: assertNull(CSS.getAttribute("position"));
087: assertNull(CSS.getAttribute("cursor"));
088: assertNull(CSS.getAttribute("border-collapse"));
089:
090: if (!isHarmony()) {
091: // These properties are defined somewhere but they're not public
092: assertNotNull(CSS.getAttribute("border-spacing"));
093: assertNotNull(CSS.getAttribute("caption-side"));
094: }
095:
096: // Standard properties defined in CSS Level 1
097: assertSame(Attribute.BACKGROUND, CSS.getAttribute("background"));
098: assertSame(Attribute.BACKGROUND_ATTACHMENT, CSS
099: .getAttribute("background-attachment"));
100: assertSame(Attribute.BACKGROUND_COLOR, CSS
101: .getAttribute("background-color"));
102: assertSame(Attribute.BACKGROUND_IMAGE, CSS
103: .getAttribute("background-image"));
104: assertSame(Attribute.BACKGROUND_POSITION, CSS
105: .getAttribute("background-position"));
106: assertSame(Attribute.BACKGROUND_REPEAT, CSS
107: .getAttribute("background-repeat"));
108: assertSame(Attribute.BORDER, CSS.getAttribute("border"));
109: assertSame(Attribute.BORDER_BOTTOM, CSS
110: .getAttribute("border-bottom"));
111: assertSame(Attribute.BORDER_BOTTOM_WIDTH, CSS
112: .getAttribute("border-bottom-width"));
113: assertSame(Attribute.BORDER_COLOR, CSS
114: .getAttribute("border-color"));
115: assertSame(Attribute.BORDER_LEFT, CSS
116: .getAttribute("border-left"));
117: assertSame(Attribute.BORDER_LEFT_WIDTH, CSS
118: .getAttribute("border-left-width"));
119: assertSame(Attribute.BORDER_RIGHT, CSS
120: .getAttribute("border-right"));
121: assertSame(Attribute.BORDER_RIGHT_WIDTH, CSS
122: .getAttribute("border-right-width"));
123: assertSame(Attribute.BORDER_STYLE, CSS
124: .getAttribute("border-style"));
125: assertSame(Attribute.BORDER_TOP, CSS.getAttribute("border-top"));
126: assertSame(Attribute.BORDER_TOP_WIDTH, CSS
127: .getAttribute("border-top-width"));
128: assertSame(Attribute.BORDER_WIDTH, CSS
129: .getAttribute("border-width"));
130: assertSame(Attribute.CLEAR, CSS.getAttribute("clear"));
131: assertSame(Attribute.COLOR, CSS.getAttribute("color"));
132: assertSame(Attribute.DISPLAY, CSS.getAttribute("display"));
133: assertSame(Attribute.FLOAT, CSS.getAttribute("float"));
134: assertSame(Attribute.FONT, CSS.getAttribute("font"));
135: assertSame(Attribute.FONT_FAMILY, CSS
136: .getAttribute("font-family"));
137: assertSame(Attribute.FONT_SIZE, CSS.getAttribute("font-size"));
138: assertSame(Attribute.FONT_STYLE, CSS.getAttribute("font-style"));
139: assertSame(Attribute.FONT_VARIANT, CSS
140: .getAttribute("font-variant"));
141: assertSame(Attribute.FONT_WEIGHT, CSS
142: .getAttribute("font-weight"));
143: assertSame(Attribute.HEIGHT, CSS.getAttribute("height"));
144: assertSame(Attribute.LETTER_SPACING, CSS
145: .getAttribute("letter-spacing"));
146: assertSame(Attribute.LINE_HEIGHT, CSS
147: .getAttribute("line-height"));
148: assertSame(Attribute.LIST_STYLE, CSS.getAttribute("list-style"));
149: assertSame(Attribute.LIST_STYLE_IMAGE, CSS
150: .getAttribute("list-style-image"));
151: assertSame(Attribute.LIST_STYLE_POSITION, CSS
152: .getAttribute("list-style-position"));
153: assertSame(Attribute.LIST_STYLE_TYPE, CSS
154: .getAttribute("list-style-type"));
155: assertSame(Attribute.MARGIN, CSS.getAttribute("margin"));
156: assertSame(Attribute.MARGIN_BOTTOM, CSS
157: .getAttribute("margin-bottom"));
158: assertSame(Attribute.MARGIN_LEFT, CSS
159: .getAttribute("margin-left"));
160: assertSame(Attribute.MARGIN_RIGHT, CSS
161: .getAttribute("margin-right"));
162: assertSame(Attribute.MARGIN_TOP, CSS.getAttribute("margin-top"));
163: assertSame(Attribute.PADDING, CSS.getAttribute("padding"));
164: assertSame(Attribute.PADDING_BOTTOM, CSS
165: .getAttribute("padding-bottom"));
166: assertSame(Attribute.PADDING_LEFT, CSS
167: .getAttribute("padding-left"));
168: assertSame(Attribute.PADDING_RIGHT, CSS
169: .getAttribute("padding-right"));
170: assertSame(Attribute.PADDING_TOP, CSS
171: .getAttribute("padding-top"));
172: assertSame(Attribute.TEXT_ALIGN, CSS.getAttribute("text-align"));
173: assertSame(Attribute.TEXT_DECORATION, CSS
174: .getAttribute("text-decoration"));
175: assertSame(Attribute.TEXT_INDENT, CSS
176: .getAttribute("text-indent"));
177: assertSame(Attribute.TEXT_TRANSFORM, CSS
178: .getAttribute("text-transform"));
179: assertSame(Attribute.VERTICAL_ALIGN, CSS
180: .getAttribute("vertical-align"));
181: assertSame(Attribute.WHITE_SPACE, CSS
182: .getAttribute("white-space"));
183: assertSame(Attribute.WIDTH, CSS.getAttribute("width"));
184: assertSame(Attribute.WORD_SPACING, CSS
185: .getAttribute("word-spacing"));
186: }
187:
188: public void testStaticAttributeKeys() {
189: final Attribute[] attrs = CSS.getAllAttributeKeys();
190: for (int i = 0; i < attrs.length; i++) {
191: Object staticKey = StyleContext
192: .getStaticAttributeKey(attrs[i]);
193: assertSame("Static attribute for " + attrs[i] + ", index "
194: + i, attrs[i], StyleContext
195: .getStaticAttribute(staticKey));
196: }
197: }
198:
199: public void testSerializable() throws IOException,
200: ClassNotFoundException {
201: CSS css = new CSS();
202: CSS read = (CSS) serializeObject(css);
203: assertNotNull(read);
204: }
205: }
|