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_TextDecorationTest 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 testUnderline() {
048: attr = ss.addAttribute(empty, StyleConstants.Underline,
049: Boolean.TRUE);
050:
051: Enumeration names = attr.getAttributeNames();
052: Object name = names.nextElement();
053: assertSame(Attribute.TEXT_DECORATION, name);
054: assertFalse(names.hasMoreElements());
055:
056: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
057: scValue = attr.getAttribute(StyleConstants.Underline);
058: assertSame(Boolean.class, scValue.getClass());
059: assertNotSame(Boolean.class, cssValue.getClass());
060: assertNotSame(String.class, cssValue.getClass());
061: assertEquals("underline", cssValue.toString());
062: assertTrue(((Boolean) scValue).booleanValue());
063: }
064:
065: public void testUnderlineFalse() {
066: attr = ss.addAttribute(empty, StyleConstants.Underline,
067: Boolean.FALSE);
068:
069: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
070: scValue = attr.getAttribute(StyleConstants.Underline);
071: assertEquals(isHarmony() ? "none" : "", cssValue.toString());
072: assertFalse(((Boolean) scValue).booleanValue());
073: }
074:
075: public void testStrikeThrough() {
076: attr = ss.addAttribute(empty, StyleConstants.StrikeThrough,
077: Boolean.TRUE);
078:
079: Enumeration names = attr.getAttributeNames();
080: Object name = names.nextElement();
081: assertSame(Attribute.TEXT_DECORATION, name);
082: assertFalse(names.hasMoreElements());
083:
084: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
085: scValue = attr.getAttribute(StyleConstants.StrikeThrough);
086: assertSame(Boolean.class, scValue.getClass());
087: assertNotSame(Boolean.class, cssValue.getClass());
088: assertNotSame(String.class, cssValue.getClass());
089: assertEquals("line-through", cssValue.toString());
090: assertTrue(((Boolean) scValue).booleanValue());
091: }
092:
093: public void testStrikeThroughFalse() {
094: attr = ss.addAttribute(empty, StyleConstants.StrikeThrough,
095: Boolean.FALSE);
096:
097: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
098: scValue = attr.getAttribute(StyleConstants.StrikeThrough);
099: assertEquals(isHarmony() ? "none" : "", cssValue.toString());
100: assertFalse(((Boolean) scValue).booleanValue());
101: }
102:
103: public void testTextDecorationNone() throws Exception {
104: ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION, "none");
105: attr = ss.createSmallAttributeSet(simple);
106:
107: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
108: assertEquals("none", cssValue.toString());
109:
110: scValue = attr.getAttribute(StyleConstants.Underline);
111: assertFalse(((Boolean) scValue).booleanValue());
112:
113: scValue = attr.getAttribute(StyleConstants.StrikeThrough);
114: assertFalse(((Boolean) scValue).booleanValue());
115: }
116:
117: public void testTextDecorationUnderline() throws Exception {
118: ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION,
119: "underline");
120: attr = ss.createSmallAttributeSet(simple);
121:
122: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
123: assertEquals("underline", cssValue.toString());
124:
125: scValue = attr.getAttribute(StyleConstants.Underline);
126: assertTrue(((Boolean) scValue).booleanValue());
127:
128: scValue = attr.getAttribute(StyleConstants.StrikeThrough);
129: assertFalse(((Boolean) scValue).booleanValue());
130: }
131:
132: public void testTextDecorationLineThrough() throws Exception {
133: ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION,
134: "line-through");
135: attr = ss.createSmallAttributeSet(simple);
136:
137: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
138: assertEquals("line-through", cssValue.toString());
139:
140: scValue = attr.getAttribute(StyleConstants.Underline);
141: assertFalse(((Boolean) scValue).booleanValue());
142:
143: scValue = attr.getAttribute(StyleConstants.StrikeThrough);
144: assertTrue(((Boolean) scValue).booleanValue());
145: }
146:
147: public void testTextDecorationUnderlineLineThrough()
148: throws Exception {
149: ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION,
150: "underline line-through");
151: attr = ss.createSmallAttributeSet(simple);
152:
153: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
154: assertEquals("underline line-through", cssValue.toString());
155:
156: scValue = attr.getAttribute(StyleConstants.Underline);
157: assertTrue(((Boolean) scValue).booleanValue());
158:
159: scValue = attr.getAttribute(StyleConstants.StrikeThrough);
160: assertTrue(((Boolean) scValue).booleanValue());
161: }
162:
163: public void testTextDecorationUnderlineThenLineThrough()
164: throws Exception {
165: ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION,
166: "underline");
167: assertEquals(1, simple.getAttributeCount());
168: ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION,
169: "line-through");
170: assertEquals(1, simple.getAttributeCount());
171:
172: cssValue = simple.getAttribute(Attribute.TEXT_DECORATION);
173: assertEquals("line-through", cssValue.toString());
174: }
175:
176: public void testTextDecorationUnderlineLineThroughSC()
177: throws Exception {
178: attr = ss.addAttribute(empty, StyleConstants.Underline,
179: Boolean.TRUE);
180: assertEquals(1, attr.getAttributeCount());
181: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
182: assertEquals("underline", cssValue.toString());
183: scValue = attr.getAttribute(StyleConstants.Underline);
184: assertTrue(((Boolean) scValue).booleanValue());
185: scValue = attr.getAttribute(StyleConstants.StrikeThrough);
186: assertFalse(((Boolean) scValue).booleanValue());
187:
188: attr = ss.addAttribute(attr, StyleConstants.StrikeThrough,
189: Boolean.TRUE);
190: assertEquals(1, attr.getAttributeCount());
191: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
192: if (isHarmony()) {
193: assertEquals("underline line-through", cssValue.toString());
194: scValue = attr.getAttribute(StyleConstants.Underline);
195: assertTrue(((Boolean) scValue).booleanValue());
196: scValue = attr.getAttribute(StyleConstants.StrikeThrough);
197: assertTrue(((Boolean) scValue).booleanValue());
198: } else {
199: assertEquals("line-through", cssValue.toString());
200: scValue = attr.getAttribute(StyleConstants.Underline);
201: assertFalse(((Boolean) scValue).booleanValue());
202: scValue = attr.getAttribute(StyleConstants.StrikeThrough);
203: assertTrue(((Boolean) scValue).booleanValue());
204: }
205: }
206:
207: public void testTextDecorationStrikeThrough() throws Exception {
208: ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION,
209: "strike-through");
210: if (isHarmony()) {
211: assertEquals(0, simple.getAttributeCount());
212: return;
213: }
214:
215: attr = ss.createSmallAttributeSet(simple);
216:
217: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
218: assertEquals("strike-through", cssValue.toString());
219:
220: scValue = attr.getAttribute(StyleConstants.Underline);
221: assertFalse(((Boolean) scValue).booleanValue());
222:
223: scValue = attr.getAttribute(StyleConstants.StrikeThrough);
224: assertFalse(((Boolean) scValue).booleanValue());
225: }
226:
227: public void testTextDecorationOverline() throws Exception {
228: ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION,
229: "overline");
230: attr = ss.createSmallAttributeSet(simple);
231:
232: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
233: assertEquals("overline", cssValue.toString());
234:
235: scValue = attr.getAttribute(StyleConstants.Underline);
236: assertFalse(((Boolean) scValue).booleanValue());
237:
238: scValue = attr.getAttribute(StyleConstants.StrikeThrough);
239: assertFalse(((Boolean) scValue).booleanValue());
240: }
241:
242: public void testTextDecorationBlink() throws Exception {
243: ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION, "blink");
244: attr = ss.createSmallAttributeSet(simple);
245:
246: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
247: assertEquals("blink", cssValue.toString());
248:
249: scValue = attr.getAttribute(StyleConstants.Underline);
250: assertFalse(((Boolean) scValue).booleanValue());
251:
252: scValue = attr.getAttribute(StyleConstants.StrikeThrough);
253: assertFalse(((Boolean) scValue).booleanValue());
254: }
255:
256: public void testAddAttributesUnderline() throws Exception {
257: simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
258: attr = ss.addAttributes(empty, simple);
259:
260: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
261: assertEquals("underline", cssValue.toString());
262:
263: scValue = attr.getAttribute(StyleConstants.Underline);
264: assertTrue(((Boolean) scValue).booleanValue());
265:
266: scValue = attr.getAttribute(StyleConstants.StrikeThrough);
267: assertFalse(((Boolean) scValue).booleanValue());
268: }
269:
270: public void testAddAttributesStrikeThrough() throws Exception {
271: simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
272: attr = ss.addAttributes(empty, simple);
273:
274: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
275: assertEquals("line-through", cssValue.toString());
276:
277: scValue = attr.getAttribute(StyleConstants.Underline);
278: assertFalse(((Boolean) scValue).booleanValue());
279:
280: scValue = attr.getAttribute(StyleConstants.StrikeThrough);
281: assertTrue(((Boolean) scValue).booleanValue());
282: }
283:
284: public void testAddAttributesUnderlineStrikeThrough()
285: throws Exception {
286: attr = ss.addAttribute(empty, StyleConstants.Underline,
287: Boolean.TRUE);
288: simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
289: attr = ss.addAttributes(attr, simple);
290:
291: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
292: if (isHarmony()) {
293: assertEquals("underline line-through", cssValue.toString());
294: scValue = attr.getAttribute(StyleConstants.Underline);
295: assertTrue(((Boolean) scValue).booleanValue());
296: scValue = attr.getAttribute(StyleConstants.StrikeThrough);
297: assertTrue(((Boolean) scValue).booleanValue());
298: } else {
299: assertTrue("underline".equals(cssValue.toString())
300: ^ "line-through".equals(cssValue.toString()));
301: }
302: }
303:
304: public void testAddAttributesStrikeThroughUnderline()
305: throws Exception {
306: simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
307: simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
308: assertEquals(2, simple.getAttributeCount());
309:
310: attr = ss.addAttributes(empty, simple);
311: assertEquals(1, attr.getAttributeCount());
312:
313: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
314: if (isHarmony()) {
315: assertEquals("underline line-through", cssValue.toString());
316: scValue = attr.getAttribute(StyleConstants.Underline);
317: assertTrue(((Boolean) scValue).booleanValue());
318: scValue = attr.getAttribute(StyleConstants.StrikeThrough);
319: assertTrue(((Boolean) scValue).booleanValue());
320: } else {
321: assertTrue("underline".equals(cssValue.toString())
322: ^ "line-through".equals(cssValue.toString()));
323: }
324: }
325:
326: public void testIsDefinedUnderline() throws Exception {
327: attr = ss.addAttribute(empty, StyleConstants.Underline,
328: Boolean.TRUE);
329:
330: assertTrue(attr.isDefined(Attribute.TEXT_DECORATION));
331: assertTrue(attr.isDefined(StyleConstants.Underline));
332: assertTrue(attr.isDefined(StyleConstants.StrikeThrough));
333: }
334:
335: public void testIsDefinedStrikeThrough() throws Exception {
336: attr = ss.addAttribute(empty, StyleConstants.StrikeThrough,
337: Boolean.TRUE);
338:
339: assertTrue(attr.isDefined(Attribute.TEXT_DECORATION));
340: assertTrue(attr.isDefined(StyleConstants.Underline));
341: assertTrue(attr.isDefined(StyleConstants.StrikeThrough));
342: }
343:
344: public void testContainsAttributeUnderline() throws Exception {
345: attr = ss.addAttribute(empty, StyleConstants.Underline,
346: Boolean.TRUE);
347:
348: assertTrue(attr.containsAttribute(StyleConstants.Underline,
349: Boolean.TRUE));
350: assertFalse(attr.containsAttribute(StyleConstants.Underline,
351: Boolean.FALSE));
352: assertFalse(attr.containsAttribute(
353: StyleConstants.StrikeThrough, Boolean.TRUE));
354: assertTrue(attr.containsAttribute(StyleConstants.StrikeThrough,
355: Boolean.FALSE));
356: }
357:
358: public void testContainsAttributeStrikeThrough() throws Exception {
359: attr = ss.addAttribute(empty, StyleConstants.StrikeThrough,
360: Boolean.TRUE);
361:
362: assertFalse(attr.containsAttribute(StyleConstants.Underline,
363: Boolean.TRUE));
364: assertTrue(attr.containsAttribute(StyleConstants.Underline,
365: Boolean.FALSE));
366: assertTrue(attr.containsAttribute(StyleConstants.StrikeThrough,
367: Boolean.TRUE));
368: assertFalse(attr.containsAttribute(
369: StyleConstants.StrikeThrough, Boolean.FALSE));
370: }
371:
372: public void testContainsAttributeUnderlineStrikeThrough()
373: throws Exception {
374: if (!isHarmony()) {
375: return;
376: }
377:
378: attr = ss.addAttribute(empty, StyleConstants.Underline,
379: Boolean.TRUE);
380: attr = ss.addAttribute(attr, StyleConstants.StrikeThrough,
381: Boolean.TRUE);
382:
383: assertTrue(attr.containsAttribute(StyleConstants.Underline,
384: Boolean.TRUE));
385: assertFalse(attr.containsAttribute(StyleConstants.Underline,
386: Boolean.FALSE));
387: assertTrue(attr.containsAttribute(StyleConstants.StrikeThrough,
388: Boolean.TRUE));
389: assertFalse(attr.containsAttribute(
390: StyleConstants.StrikeThrough, Boolean.FALSE));
391: }
392:
393: public void testContainsAttributesUnderline() throws Exception {
394: simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
395: attr = ss.addAttributes(empty, simple);
396: assertTrue(attr.containsAttributes(simple));
397:
398: simple.removeAttribute(StyleConstants.Underline);
399: simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
400: assertFalse(attr.containsAttributes(simple));
401: }
402:
403: public void testContainsAttributesUnderlineFalse() throws Exception {
404: attr = ss.addAttribute(empty, StyleConstants.Underline,
405: Boolean.TRUE);
406: assertTrue(attr.containsAttributes(simple));
407:
408: simple
409: .addAttribute(StyleConstants.StrikeThrough,
410: Boolean.FALSE);
411: assertTrue(attr.containsAttributes(simple));
412: }
413:
414: public void testContainsAttributesStrikeThrough() throws Exception {
415: simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
416: attr = ss.addAttributes(empty, simple);
417: assertTrue(attr.containsAttributes(simple));
418:
419: simple.removeAttribute(StyleConstants.StrikeThrough);
420: simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
421: assertFalse(attr.containsAttributes(simple));
422: }
423:
424: public void testContainsAttributesStrikeThroughFalse()
425: throws Exception {
426: attr = ss.addAttribute(empty, StyleConstants.StrikeThrough,
427: Boolean.TRUE);
428:
429: simple.addAttribute(StyleConstants.Underline, Boolean.FALSE);
430: assertTrue(attr.containsAttributes(simple));
431: }
432:
433: public void testContainsAttributesUnderlineStrikeThrough()
434: throws Exception {
435:
436: if (!isHarmony()) {
437: return;
438: }
439:
440: simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
441: simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
442: attr = ss.addAttributes(empty, simple);
443:
444: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
445: assertEquals("underline line-through", cssValue.toString());
446:
447: assertTrue(attr.containsAttributes(simple));
448:
449: simple.removeAttribute(StyleConstants.StrikeThrough);
450: assertTrue(attr.containsAttributes(simple));
451: }
452:
453: public void testRemoveAttributeUnderline() throws Exception {
454: attr = ss.addAttribute(empty, StyleConstants.Underline,
455: Boolean.TRUE);
456: assertEquals(1, attr.getAttributeCount());
457:
458: attr = ss.removeAttribute(attr, StyleConstants.StrikeThrough);
459: if (isHarmony()) {
460: assertEquals(1, attr.getAttributeCount());
461: } else {
462: assertEquals(0, attr.getAttributeCount());
463: return;
464: }
465:
466: attr = ss.removeAttribute(attr, StyleConstants.Underline);
467: assertEquals(0, attr.getAttributeCount());
468: }
469:
470: public void testRemoveAttributeStrikeThrough() throws Exception {
471: attr = ss.addAttribute(empty, StyleConstants.StrikeThrough,
472: Boolean.TRUE);
473:
474: attr = ss.removeAttribute(attr, StyleConstants.Underline);
475: if (isHarmony()) {
476: assertEquals(1, attr.getAttributeCount());
477: } else {
478: assertEquals(0, attr.getAttributeCount());
479: return;
480: }
481:
482: attr = ss.removeAttribute(attr, StyleConstants.StrikeThrough);
483: assertEquals(0, attr.getAttributeCount());
484: }
485:
486: public void testRemoveAttributesUnderline() throws Exception {
487: simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
488: attr = ss.addAttributes(empty, simple);
489: assertTrue(attr.containsAttributes(simple));
490:
491: attr = ss.removeAttributes(attr, simple);
492: if (isHarmony()) {
493: assertEquals(0, attr.getAttributeCount());
494: } else {
495: assertEquals(1, attr.getAttributeCount());
496: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
497: assertEquals("underline", cssValue.toString());
498: }
499: }
500:
501: public void testRemoveAttributesStrikeThrough() throws Exception {
502: simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
503: attr = ss.addAttributes(empty, simple);
504: assertTrue(attr.containsAttributes(simple));
505:
506: attr = ss.removeAttributes(attr, simple);
507: if (isHarmony()) {
508: assertEquals(0, attr.getAttributeCount());
509: } else {
510: assertEquals(1, attr.getAttributeCount());
511: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
512: assertEquals("line-through", cssValue.toString());
513: }
514: }
515:
516: public void testRemoveAttributesUnderlineStrikeThrough01()
517: throws Exception {
518:
519: if (!isHarmony()) {
520: return;
521: }
522:
523: simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
524: simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
525: attr = ss.addAttributes(empty, simple);
526:
527: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
528: assertEquals("underline line-through", cssValue.toString());
529:
530: assertTrue(attr.containsAttributes(simple));
531:
532: attr = ss.removeAttributes(attr, simple);
533: assertEquals(0, attr.getAttributeCount());
534: }
535:
536: public void testRemoveAttributesUnderlineStrikeThrough02()
537: throws Exception {
538:
539: if (!isHarmony()) {
540: return;
541: }
542:
543: simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
544: simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
545: attr = ss.addAttributes(empty, simple);
546:
547: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
548: assertEquals("underline line-through", cssValue.toString());
549:
550: simple.removeAttribute(StyleConstants.Underline);
551: attr = ss.removeAttributes(attr, simple);
552: assertEquals(1, attr.getAttributeCount());
553: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
554: assertEquals("underline", cssValue.toString());
555: }
556:
557: public void testRemoveAttributesUnderlineStrikeThrough03()
558: throws Exception {
559:
560: if (!isHarmony()) {
561: return;
562: }
563:
564: simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
565: simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
566: attr = ss.addAttributes(empty, simple);
567:
568: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
569: assertEquals("underline line-through", cssValue.toString());
570:
571: simple.removeAttribute(StyleConstants.StrikeThrough);
572: attr = ss.removeAttributes(attr, simple);
573: assertEquals(1, attr.getAttributeCount());
574: cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
575: assertEquals("line-through", cssValue.toString());
576: }
577: }
|