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 javax.swing.BasicSwingTestCase;
023: import javax.swing.text.MutableAttributeSet;
024: import javax.swing.text.SimpleAttributeSet;
025: import javax.swing.text.html.CSS.Attribute;
026:
027: public abstract class StyleSheet_ConvertAttr_BorderPartTestCase extends
028: BasicSwingTestCase {
029: protected StyleSheet ss;
030: protected MutableAttributeSet simple;
031: protected Attribute cssKey;
032: protected Object cssValue;
033: protected Attribute cssWidthKey;
034: protected int sideIndex;
035:
036: protected void setUp() throws Exception {
037: super .setUp();
038: ss = new StyleSheet();
039: simple = new SimpleAttributeSet();
040: sideIndex = -1;
041: }
042:
043: public void testBlackSolidThin() throws Exception {
044: ss.addCSSAttribute(simple, cssKey, "black solid thin");
045: cssValue = simple.getAttribute(cssKey);
046: if (!isHarmony()) {
047: assertSame(String.class, cssValue.getClass());
048: assertEquals("black solid thin", cssValue.toString());
049: return;
050: }
051:
052: assertNull(cssValue);
053: assertEquals(3, simple.getAttributeCount());
054:
055: assertEquals(getColorDeclaration("black"), simple.getAttribute(
056: Attribute.BORDER_COLOR).toString());
057: assertEquals(getStyleDeclaration("solid"), simple.getAttribute(
058: Attribute.BORDER_STYLE).toString());
059: assertEquals("thin", simple.getAttribute(cssWidthKey)
060: .toString());
061: }
062:
063: public void testSolidThin() throws Exception {
064: ss.addCSSAttribute(simple, cssKey, "solid thin");
065: cssValue = simple.getAttribute(cssKey);
066: if (!isHarmony()) {
067: assertSame(String.class, cssValue.getClass());
068: assertEquals("solid thin", cssValue.toString());
069: return;
070: }
071:
072: assertNull(cssValue);
073: assertEquals(2, simple.getAttributeCount());
074:
075: assertEquals(getStyleDeclaration("solid"), simple.getAttribute(
076: Attribute.BORDER_STYLE).toString());
077: assertEquals("thin", simple.getAttribute(cssWidthKey)
078: .toString());
079: }
080:
081: public void testBlackThin() throws Exception {
082: ss.addCSSAttribute(simple, cssKey, "black thin");
083: cssValue = simple.getAttribute(cssKey);
084: if (!isHarmony()) {
085: assertSame(String.class, cssValue.getClass());
086: assertEquals("black thin", cssValue.toString());
087: return;
088: }
089:
090: assertNull(cssValue);
091: assertEquals(2, simple.getAttributeCount());
092:
093: assertEquals(getColorDeclaration("black"), simple.getAttribute(
094: Attribute.BORDER_COLOR).toString());
095: assertEquals("thin", simple.getAttribute(cssWidthKey)
096: .toString());
097: }
098:
099: public void testBlackSolid() throws Exception {
100: ss.addCSSAttribute(simple, cssKey, "black solid");
101: cssValue = simple.getAttribute(cssKey);
102: if (!isHarmony()) {
103: assertSame(String.class, cssValue.getClass());
104: assertEquals("black solid", cssValue.toString());
105: return;
106: }
107:
108: assertNull(cssValue);
109: assertEquals(2, simple.getAttributeCount());
110:
111: assertEquals(getColorDeclaration("black"), simple.getAttribute(
112: Attribute.BORDER_COLOR).toString());
113: assertEquals(getStyleDeclaration("solid"), simple.getAttribute(
114: Attribute.BORDER_STYLE).toString());
115: }
116:
117: public void testSolidBlackThin() throws Exception {
118: ss.addCSSAttribute(simple, cssKey, "solid black thin");
119: cssValue = simple.getAttribute(cssKey);
120: if (!isHarmony()) {
121: assertSame(String.class, cssValue.getClass());
122: assertEquals("solid black thin", cssValue.toString());
123: return;
124: }
125:
126: assertNull(cssValue);
127: assertEquals(3, simple.getAttributeCount());
128:
129: assertEquals(getColorDeclaration("black"), simple.getAttribute(
130: Attribute.BORDER_COLOR).toString());
131: assertEquals(getStyleDeclaration("solid"), simple.getAttribute(
132: Attribute.BORDER_STYLE).toString());
133: assertEquals("thin", simple.getAttribute(cssWidthKey)
134: .toString());
135: }
136:
137: public void testSolidFFEEDDThin() throws Exception {
138: ss.addCSSAttribute(simple, cssKey, "solid #FFEEDD thin");
139: cssValue = simple.getAttribute(cssKey);
140: if (!isHarmony()) {
141: assertSame(String.class, cssValue.getClass());
142: assertEquals("solid #FFEEDD thin", cssValue.toString());
143: return;
144: }
145:
146: assertNull(cssValue);
147: assertEquals(3, simple.getAttributeCount());
148:
149: assertEquals(getColorDeclaration("#FFEEDD"), simple
150: .getAttribute(Attribute.BORDER_COLOR).toString());
151: assertEquals(getStyleDeclaration("solid"), simple.getAttribute(
152: Attribute.BORDER_STYLE).toString());
153: assertEquals("thin", simple.getAttribute(cssWidthKey)
154: .toString());
155: }
156:
157: public void testSolidRGBMedium() throws Exception {
158: ss.addCSSAttribute(simple, cssKey,
159: "solid rgb(127, 255, 75) medium");
160: cssValue = simple.getAttribute(cssKey);
161: if (!isHarmony()) {
162: assertSame(String.class, cssValue.getClass());
163: assertEquals("solid rgb(127, 255, 75) medium", cssValue
164: .toString());
165: return;
166: }
167:
168: assertNull(cssValue);
169: assertEquals(3, simple.getAttributeCount());
170:
171: assertEquals(getColorDeclaration("rgb(127, 255, 75)"), simple
172: .getAttribute(Attribute.BORDER_COLOR).toString());
173: assertEquals(getStyleDeclaration("solid"), simple.getAttribute(
174: Attribute.BORDER_STYLE).toString());
175: assertEquals("medium", simple.getAttribute(cssWidthKey)
176: .toString());
177: }
178:
179: public void testInsetRGBLength() throws Exception {
180: ss.addCSSAttribute(simple, cssKey,
181: "inset rgb(50%, 100%, 30%) 1px");
182: cssValue = simple.getAttribute(cssKey);
183: if (!isHarmony()) {
184: assertSame(String.class, cssValue.getClass());
185: assertEquals("inset rgb(50%, 100%, 30%) 1px", cssValue
186: .toString());
187: return;
188: }
189:
190: assertNull(cssValue);
191: assertEquals(3, simple.getAttributeCount());
192:
193: assertEquals(getColorDeclaration("rgb(50%, 100%, 30%)"), simple
194: .getAttribute(Attribute.BORDER_COLOR).toString());
195: assertEquals(getStyleDeclaration("inset"), simple.getAttribute(
196: Attribute.BORDER_STYLE).toString());
197: assertEquals("1px", simple.getAttribute(cssWidthKey).toString());
198: }
199:
200: protected final String getStyleDeclaration(final String style) {
201: StringBuffer result = new StringBuffer();
202: for (int i = 0; i < 4; i++) {
203: if (i > 0) {
204: result.append(' ');
205: }
206: result.append(i == sideIndex ? style : "none");
207: }
208: return result.toString();
209: }
210:
211: protected final String getColorDeclaration(final String color) {
212: StringBuffer result = new StringBuffer();
213: for (int i = 0; i < 4; i++) {
214: if (i > 0) {
215: result.append(' ');
216: }
217: result.append(i == sideIndex ? color : "white");
218: }
219: return result.toString();
220: }
221: }
|