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 class StyleSheet_ConvertAttr_BorderTest extends
028: BasicSwingTestCase {
029: private StyleSheet ss;
030: private MutableAttributeSet simple;
031: private Object cssValue;
032:
033: protected void setUp() throws Exception {
034: super .setUp();
035: ss = new StyleSheet();
036: simple = new SimpleAttributeSet();
037: }
038:
039: public void testBorderThin() throws Exception {
040: ss.addCSSAttribute(simple, Attribute.BORDER, "thin");
041: cssValue = simple.getAttribute(Attribute.BORDER);
042: if (!isHarmony()) {
043: assertSame(String.class, cssValue.getClass());
044: assertEquals("thin", cssValue.toString());
045: return;
046: }
047:
048: assertNull(cssValue);
049: assertEquals(4, simple.getAttributeCount());
050:
051: assertEquals("thin", simple.getAttribute(
052: Attribute.BORDER_TOP_WIDTH).toString());
053: assertEquals("thin", simple.getAttribute(
054: Attribute.BORDER_RIGHT_WIDTH).toString());
055: assertEquals("thin", simple.getAttribute(
056: Attribute.BORDER_BOTTOM_WIDTH).toString());
057: assertEquals("thin", simple.getAttribute(
058: Attribute.BORDER_LEFT_WIDTH).toString());
059: }
060:
061: public void testBorderGreen() throws Exception {
062: ss.addCSSAttribute(simple, Attribute.BORDER, "green");
063: cssValue = simple.getAttribute(Attribute.BORDER);
064: if (!isHarmony()) {
065: assertSame(String.class, cssValue.getClass());
066: assertEquals("green", cssValue.toString());
067: return;
068: }
069:
070: assertNull(cssValue);
071: assertEquals(1, simple.getAttributeCount());
072:
073: assertEquals("green", simple.getAttribute(
074: Attribute.BORDER_COLOR).toString());
075: }
076:
077: public void testBorderSolid() throws Exception {
078: ss.addCSSAttribute(simple, Attribute.BORDER, "solid");
079: cssValue = simple.getAttribute(Attribute.BORDER);
080: if (!isHarmony()) {
081: assertSame(String.class, cssValue.getClass());
082: assertEquals("solid", cssValue.toString());
083: return;
084: }
085:
086: assertNull(cssValue);
087: assertEquals(1, simple.getAttributeCount());
088:
089: assertEquals("solid", simple.getAttribute(
090: Attribute.BORDER_STYLE).toString());
091: }
092:
093: public void testBorderThinYellow() throws Exception {
094: ss.addCSSAttribute(simple, Attribute.BORDER, "thin yellow");
095: cssValue = simple.getAttribute(Attribute.BORDER);
096: if (!isHarmony()) {
097: assertSame(String.class, cssValue.getClass());
098: assertEquals("thin yellow", cssValue.toString());
099: return;
100: }
101:
102: assertNull(cssValue);
103: assertEquals(5, simple.getAttributeCount());
104:
105: assertEquals("yellow", simple.getAttribute(
106: Attribute.BORDER_COLOR).toString());
107: assertEquals("thin", simple.getAttribute(
108: Attribute.BORDER_TOP_WIDTH).toString());
109: assertEquals("thin", simple.getAttribute(
110: Attribute.BORDER_RIGHT_WIDTH).toString());
111: assertEquals("thin", simple.getAttribute(
112: Attribute.BORDER_BOTTOM_WIDTH).toString());
113: assertEquals("thin", simple.getAttribute(
114: Attribute.BORDER_LEFT_WIDTH).toString());
115: }
116:
117: public void testBorderThinDotted() throws Exception {
118: ss.addCSSAttribute(simple, Attribute.BORDER, "thin dotted");
119: cssValue = simple.getAttribute(Attribute.BORDER);
120: if (!isHarmony()) {
121: assertSame(String.class, cssValue.getClass());
122: assertEquals("thin dotted", cssValue.toString());
123: return;
124: }
125:
126: assertNull(cssValue);
127: assertEquals(5, simple.getAttributeCount());
128:
129: assertEquals("dotted", simple.getAttribute(
130: Attribute.BORDER_STYLE).toString());
131: assertEquals("thin", simple.getAttribute(
132: Attribute.BORDER_TOP_WIDTH).toString());
133: assertEquals("thin", simple.getAttribute(
134: Attribute.BORDER_RIGHT_WIDTH).toString());
135: assertEquals("thin", simple.getAttribute(
136: Attribute.BORDER_BOTTOM_WIDTH).toString());
137: assertEquals("thin", simple.getAttribute(
138: Attribute.BORDER_LEFT_WIDTH).toString());
139: }
140:
141: public void testBorderGreenMedium() throws Exception {
142: ss.addCSSAttribute(simple, Attribute.BORDER, "green medium");
143: cssValue = simple.getAttribute(Attribute.BORDER);
144: if (!isHarmony()) {
145: assertSame(String.class, cssValue.getClass());
146: assertEquals("green medium", cssValue.toString());
147: return;
148: }
149:
150: assertNull(cssValue);
151: assertEquals(5, simple.getAttributeCount());
152:
153: assertEquals("green", simple.getAttribute(
154: Attribute.BORDER_COLOR).toString());
155: assertEquals("medium", simple.getAttribute(
156: Attribute.BORDER_TOP_WIDTH).toString());
157: assertEquals("medium", simple.getAttribute(
158: Attribute.BORDER_RIGHT_WIDTH).toString());
159: assertEquals("medium", simple.getAttribute(
160: Attribute.BORDER_BOTTOM_WIDTH).toString());
161: assertEquals("medium", simple.getAttribute(
162: Attribute.BORDER_LEFT_WIDTH).toString());
163: }
164:
165: public void testBorderGreenDashed() throws Exception {
166: ss.addCSSAttribute(simple, Attribute.BORDER, "green dashed");
167: cssValue = simple.getAttribute(Attribute.BORDER);
168: if (!isHarmony()) {
169: assertSame(String.class, cssValue.getClass());
170: assertEquals("green dashed", cssValue.toString());
171: return;
172: }
173:
174: assertNull(cssValue);
175: assertEquals(2, simple.getAttributeCount());
176:
177: assertEquals("dashed", simple.getAttribute(
178: Attribute.BORDER_STYLE).toString());
179: assertEquals("green", simple.getAttribute(
180: Attribute.BORDER_COLOR).toString());
181: }
182:
183: public void testBorderSolidRed() throws Exception {
184: ss.addCSSAttribute(simple, Attribute.BORDER, "solid red");
185: cssValue = simple.getAttribute(Attribute.BORDER);
186: if (!isHarmony()) {
187: assertSame(String.class, cssValue.getClass());
188: assertEquals("solid red", cssValue.toString());
189: return;
190: }
191:
192: assertNull(cssValue);
193: assertEquals(2, simple.getAttributeCount());
194:
195: assertEquals("red", simple.getAttribute(Attribute.BORDER_COLOR)
196: .toString());
197: assertEquals("solid", simple.getAttribute(
198: Attribute.BORDER_STYLE).toString());
199: }
200:
201: public void testBorderSolidThin() throws Exception {
202: ss.addCSSAttribute(simple, Attribute.BORDER, "solid thin");
203: cssValue = simple.getAttribute(Attribute.BORDER);
204: if (!isHarmony()) {
205: assertSame(String.class, cssValue.getClass());
206: assertEquals("solid thin", cssValue.toString());
207: return;
208: }
209:
210: assertNull(cssValue);
211: assertEquals(5, simple.getAttributeCount());
212:
213: assertEquals("solid", simple.getAttribute(
214: Attribute.BORDER_STYLE).toString());
215: assertEquals("thin", simple.getAttribute(
216: Attribute.BORDER_TOP_WIDTH).toString());
217: assertEquals("thin", simple.getAttribute(
218: Attribute.BORDER_RIGHT_WIDTH).toString());
219: assertEquals("thin", simple.getAttribute(
220: Attribute.BORDER_BOTTOM_WIDTH).toString());
221: assertEquals("thin", simple.getAttribute(
222: Attribute.BORDER_LEFT_WIDTH).toString());
223: }
224:
225: public void testBorderInsetThickAqua() throws Exception {
226: ss
227: .addCSSAttribute(simple, Attribute.BORDER,
228: "inset thick aqua");
229: cssValue = simple.getAttribute(Attribute.BORDER);
230: if (!isHarmony()) {
231: assertSame(String.class, cssValue.getClass());
232: assertEquals("inset thick aqua", cssValue.toString());
233: return;
234: }
235:
236: assertNull(cssValue);
237: assertEquals(6, simple.getAttributeCount());
238:
239: assertEquals("inset", simple.getAttribute(
240: Attribute.BORDER_STYLE).toString());
241: assertEquals("aqua", simple
242: .getAttribute(Attribute.BORDER_COLOR).toString());
243: assertEquals("thick", simple.getAttribute(
244: Attribute.BORDER_TOP_WIDTH).toString());
245: assertEquals("thick", simple.getAttribute(
246: Attribute.BORDER_RIGHT_WIDTH).toString());
247: assertEquals("thick", simple.getAttribute(
248: Attribute.BORDER_BOTTOM_WIDTH).toString());
249: assertEquals("thick", simple.getAttribute(
250: Attribute.BORDER_LEFT_WIDTH).toString());
251: }
252:
253: public void testBorderThickAquaInset() throws Exception {
254: ss
255: .addCSSAttribute(simple, Attribute.BORDER,
256: "thick aqua inset");
257: cssValue = simple.getAttribute(Attribute.BORDER);
258: if (!isHarmony()) {
259: assertSame(String.class, cssValue.getClass());
260: assertEquals("thick aqua inset", cssValue.toString());
261: return;
262: }
263:
264: assertNull(cssValue);
265: assertEquals(6, simple.getAttributeCount());
266:
267: assertEquals("inset", simple.getAttribute(
268: Attribute.BORDER_STYLE).toString());
269: assertEquals("aqua", simple
270: .getAttribute(Attribute.BORDER_COLOR).toString());
271: assertEquals("thick", simple.getAttribute(
272: Attribute.BORDER_TOP_WIDTH).toString());
273: assertEquals("thick", simple.getAttribute(
274: Attribute.BORDER_RIGHT_WIDTH).toString());
275: assertEquals("thick", simple.getAttribute(
276: Attribute.BORDER_BOTTOM_WIDTH).toString());
277: assertEquals("thick", simple.getAttribute(
278: Attribute.BORDER_LEFT_WIDTH).toString());
279: }
280:
281: public void testBorderAquaInsetThick() throws Exception {
282: ss
283: .addCSSAttribute(simple, Attribute.BORDER,
284: "aqua inset thick");
285: cssValue = simple.getAttribute(Attribute.BORDER);
286: if (!isHarmony()) {
287: assertSame(String.class, cssValue.getClass());
288: assertEquals("aqua inset thick", cssValue.toString());
289: return;
290: }
291:
292: assertNull(cssValue);
293: assertEquals(6, simple.getAttributeCount());
294:
295: assertEquals("inset", simple.getAttribute(
296: Attribute.BORDER_STYLE).toString());
297: assertEquals("aqua", simple
298: .getAttribute(Attribute.BORDER_COLOR).toString());
299: assertEquals("thick", simple.getAttribute(
300: Attribute.BORDER_TOP_WIDTH).toString());
301: assertEquals("thick", simple.getAttribute(
302: Attribute.BORDER_RIGHT_WIDTH).toString());
303: assertEquals("thick", simple.getAttribute(
304: Attribute.BORDER_BOTTOM_WIDTH).toString());
305: assertEquals("thick", simple.getAttribute(
306: Attribute.BORDER_LEFT_WIDTH).toString());
307: }
308: }
|