01: /*
02: * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
03: *
04: * The program is provided "as is" without any warranty express or
05: * implied, including the warranty of non-infringement and the implied
06: * warranties of merchantibility and fitness for a particular purpose.
07: * IBM will not be liable for any damages suffered by you as a result
08: * of using the Program. In no event will IBM be liable for any
09: * special, indirect or consequential damages or lost profits even if
10: * IBM has been advised of the possibility of their occurrence. IBM
11: * will not be liable for any third party claims against you.
12: */
13: package com.ibm.richtext.test.unit;
14:
15: import com.ibm.icu.dev.test.TestFmwk;
16: import com.ibm.richtext.textlayout.attributes.AttributeSet;
17: import java.util.Enumeration;
18:
19: public class TestAttributeSet extends TestFmwk {
20:
21: static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
22:
23: public static void main(String[] args) throws Exception {
24:
25: new TestAttributeSet().run(args);
26: }
27:
28: public void test() {
29:
30: final Object elem1 = new Object();
31: final Object elem2 = new Float(4);
32: final Object elem3 = "String";
33: final Object elem4 = Boolean.FALSE;
34:
35: AttributeSet set1 = new AttributeSet(new Object[] { elem1,
36: elem2, elem3 });
37: if (set1.size() != 3) {
38: errln("Size is wrong.");
39: }
40:
41: if (set1.contains(elem4)) {
42: errln("Set contents are wrong.");
43: }
44:
45: if (!set1.contains(elem1)) {
46: errln("Set contents are wrong.");
47: }
48:
49: AttributeSet set2 = new AttributeSet(elem4);
50:
51: if (set2.size() != 1) {
52: errln("Size is wrong.");
53: }
54:
55: if (!set2.contains(elem4)) {
56: errln("Set contents are wrong.");
57: }
58:
59: if (set2.contains(elem1)) {
60: errln("Set contents are wrong.");
61: }
62:
63: Enumeration iter = set2.elements();
64: if (!iter.nextElement().equals(elem4)) {
65: errln("Invalid object in iterator.");
66: }
67:
68: AttributeSet union = set2.unionWith(set1);
69: if (!set1.unionWith(set2).equals(union)) {
70: errln("unionWith is not commutative.");
71: }
72:
73: if (!union.contains(elem1) || !union.contains(elem4)) {
74: errln("Set contents are wrong.");
75: }
76:
77: if (!set1.addElement(elem4).equals(union)) {
78: errln("addElement is wrong.");
79: }
80:
81: if (!union.intersectWith(set1).equals(set1)) {
82: errln("intersectWith is wrong.");
83: }
84:
85: if (!union.subtract(set1).equals(set2)) {
86: errln("subtract is wrong.");
87: }
88: }
89: }
|