1 /* getRunLimit.java -- some checks for the getRunLimit() methods in the |
|
2 AttributedCharacterIterator interface. |
|
3 Copyright (C) 2006 David Gilbert <david.gilbert@object-refinery.com> |
|
4 This file is part of Mauve. |
|
5 |
|
6 Mauve is free software; you can redistribute it and/or modify |
|
7 it under the terms of the GNU General Public License as published by |
|
8 the Free Software Foundation; either version 2, or (at your option) |
|
9 any later version. |
|
10 |
|
11 Mauve is distributed in the hope that it will be useful, but |
|
12 WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 General Public License for more details. |
|
15 |
|
16 You should have received a copy of the GNU General Public License |
|
17 along with Mauve; see the file COPYING. If not, write to the |
|
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
19 02110-1301 USA. |
|
20 |
|
21 */ |
|
22 |
|
23 // Tags: JDK1.2 |
|
24 |
|
25 package gnu.testlet.java.text.AttributedCharacterIterator; |
|
26 |
|
27 import gnu.testlet.TestHarness; |
|
28 import gnu.testlet.Testlet; |
|
29 |
|
30 import java.awt.Color; |
|
31 import java.awt.font.TextAttribute; |
|
32 import java.text.AttributedCharacterIterator; |
|
33 import java.text.AttributedString; |
|
34 import java.util.HashSet; |
|
35 import java.util.Set; |
|
36 |
|
37 public class getRunLimit implements Testlet |
|
38 { |
|
39 public void test(TestHarness harness) |
|
40 { |
|
41 test1(harness); |
|
42 test2(harness); |
|
43 test3(harness); |
|
44 } |
|
45 |
|
46 public void test1(TestHarness harness) |
|
47 { |
|
48 harness.checkPoint("()"); |
|
49 AttributedString as = new AttributedString("ABCDEFGHIJ"); |
|
50 as.addAttribute(TextAttribute.LANGUAGE, "English"); |
|
51 as.addAttribute(TextAttribute.FOREGROUND, Color.red, 2, 4); |
|
52 as.addAttribute(TextAttribute.BACKGROUND, Color.blue, 7, 8); |
|
53 AttributedCharacterIterator aci = as.getIterator(); |
|
54 harness.check(aci.getRunLimit(), 2); |
|
55 aci.setIndex(2); |
|
56 harness.check(aci.getRunLimit(), 4); |
|
57 aci.setIndex(5); |
|
58 harness.check(aci.getRunLimit(), 7); |
|
59 aci.setIndex(7); |
|
60 harness.check(aci.getRunLimit(), 8); |
|
61 aci.setIndex(8); |
|
62 harness.check(aci.getRunLimit(), 10); |
|
63 |
|
64 // try an empty string |
|
65 as = new AttributedString(""); |
|
66 aci = as.getIterator(); |
|
67 harness.check(aci.getRunLimit(), 0); |
|
68 |
|
69 // try a string with no attributes |
|
70 as = new AttributedString("ABC"); |
|
71 aci = as.getIterator(); |
|
72 harness.check(aci.getRunLimit(), 3); |
|
73 } |
|
74 |
|
75 public void test2(TestHarness harness) |
|
76 { |
|
77 harness.checkPoint("(AttributedCharacterIterator.Attribute)"); |
|
78 AttributedString as = new AttributedString("ABCDEFGHIJ"); |
|
79 as.addAttribute(TextAttribute.LANGUAGE, "English"); |
|
80 as.addAttribute(TextAttribute.FOREGROUND, Color.red, 2, 4); |
|
81 AttributedCharacterIterator aci = as.getIterator(); |
|
82 harness.check(aci.getRunLimit(TextAttribute.LANGUAGE), 10); |
|
83 harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 2); |
|
84 harness.check(aci.getRunLimit(TextAttribute.BACKGROUND), 10); |
|
85 aci.setIndex(2); |
|
86 harness.check(aci.getRunLimit(TextAttribute.LANGUAGE), 10); |
|
87 harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 4); |
|
88 harness.check(aci.getRunLimit(TextAttribute.BACKGROUND), 10); |
|
89 aci.setIndex(4); |
|
90 harness.check(aci.getRunLimit(TextAttribute.LANGUAGE), 10); |
|
91 harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 10); |
|
92 harness.check(aci.getRunLimit(TextAttribute.BACKGROUND), 10); |
|
93 |
|
94 // try an empty string |
|
95 as = new AttributedString(""); |
|
96 aci = as.getIterator(); |
|
97 harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 0); |
|
98 |
|
99 // try a string with no attributes |
|
100 as = new AttributedString("ABC"); |
|
101 aci = as.getIterator(); |
|
102 harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 3); |
|
103 } |
|
104 |
|
105 public void test3(TestHarness harness) |
|
106 { |
|
107 harness.checkPoint("(Set)"); |
|
108 AttributedString as = new AttributedString("ABCDEFGHIJ"); |
|
109 as.addAttribute(TextAttribute.LANGUAGE, "English"); |
|
110 as.addAttribute(TextAttribute.FOREGROUND, Color.red, 2, 4); |
|
111 as.addAttribute(TextAttribute.BACKGROUND, Color.yellow, 3, 5); |
|
112 AttributedCharacterIterator aci = as.getIterator(); |
|
113 Set set0 = new HashSet(); |
|
114 Set set1 = new HashSet(); |
|
115 set1.add(TextAttribute.LANGUAGE); |
|
116 Set set2 = new HashSet(); |
|
117 set2.add(TextAttribute.FOREGROUND); |
|
118 set2.add(TextAttribute.BACKGROUND); |
|
119 Set set3 = new HashSet(); |
|
120 set3.add(TextAttribute.LANGUAGE); |
|
121 set3.add(TextAttribute.FOREGROUND); |
|
122 set3.add(TextAttribute.BACKGROUND); |
|
123 harness.check(aci.getRunLimit(set0), 10); |
|
124 harness.check(aci.getRunLimit(set1), 10); |
|
125 harness.check(aci.getRunLimit(set2), 2); |
|
126 harness.check(aci.getRunLimit(set3), 2); |
|
127 aci.setIndex(2); |
|
128 harness.check(aci.getRunLimit(set0), 10); |
|
129 harness.check(aci.getRunLimit(set1), 10); |
|
130 harness.check(aci.getRunLimit(set2), 3); |
|
131 harness.check(aci.getRunLimit(set3), 3); |
|
132 aci.setIndex(3); |
|
133 harness.check(aci.getRunLimit(set0), 10); |
|
134 harness.check(aci.getRunLimit(set1), 10); |
|
135 harness.check(aci.getRunLimit(set2), 4); |
|
136 harness.check(aci.getRunLimit(set3), 4); |
|
137 aci.setIndex(4); |
|
138 harness.check(aci.getRunLimit(set0), 10); |
|
139 harness.check(aci.getRunLimit(set1), 10); |
|
140 harness.check(aci.getRunLimit(set2), 5); |
|
141 harness.check(aci.getRunLimit(set3), 5); |
|
142 aci.setIndex(5); |
|
143 harness.check(aci.getRunLimit(set0), 10); |
|
144 harness.check(aci.getRunLimit(set1), 10); |
|
145 harness.check(aci.getRunLimit(set2), 10); |
|
146 harness.check(aci.getRunLimit(set3), 10); |
|
147 // try an empty string |
|
148 as = new AttributedString(""); |
|
149 aci = as.getIterator(); |
|
150 harness.check(aci.getRunLimit(set0), 0); |
|
151 harness.check(aci.getRunLimit(set1), 0); |
|
152 harness.check(aci.getRunLimit(set2), 0); |
|
153 harness.check(aci.getRunLimit(set3), 0); |
|
154 |
|
155 // try a string with no attributes |
|
156 as = new AttributedString("ABC"); |
|
157 aci = as.getIterator(); |
|
158 harness.check(aci.getRunLimit(set0), 3); |
|
159 harness.check(aci.getRunLimit(set1), 3); |
|
160 harness.check(aci.getRunLimit(set2), 3); |
|
161 harness.check(aci.getRunLimit(set3), 3); |
|
162 } |
|
163 } |
|