1 // constructor.java - Test StringCharacterIterator constructors. |
|
2 |
|
3 // Copyright (c) 1999 Cygnus Solutions |
|
4 // Written by Tom Tromey <tromey@cygnus.com> |
|
5 |
|
6 // This file is part of Mauve. |
|
7 |
|
8 // Mauve is free software; you can redistribute it and/or modify |
|
9 // it under the terms of the GNU General Public License as published by |
|
10 // the Free Software Foundation; either version 2, or (at your option) |
|
11 // any later version. |
|
12 |
|
13 // Mauve is distributed in the hope that it will be useful, |
|
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 // GNU General Public License for more details. |
|
17 |
|
18 // You should have received a copy of the GNU General Public License |
|
19 // along with Mauve; see the file COPYING. If not, write to |
|
20 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
21 // Boston, MA 02111-1307, USA. |
|
22 |
|
23 // Tags: JDK1.1 |
|
24 |
|
25 package gnu.testlet.java.text.StringCharacterIterator; |
|
26 |
|
27 import gnu.testlet.Testlet; |
|
28 import gnu.testlet.TestHarness; |
|
29 import java.text.StringCharacterIterator; |
|
30 |
|
31 public class constructor implements Testlet |
|
32 { |
|
33 public void test (TestHarness harness) |
|
34 { |
|
35 StringCharacterIterator sci = null; |
|
36 harness.checkPoint ("failing constructors"); |
|
37 |
|
38 try |
|
39 { |
|
40 sci = new StringCharacterIterator (null); |
|
41 } |
|
42 catch (NullPointerException x) |
|
43 { |
|
44 } |
|
45 harness.check (sci, null); |
|
46 |
|
47 sci = null; |
|
48 try |
|
49 { |
|
50 sci = new StringCharacterIterator (null, 0); |
|
51 } |
|
52 catch (NullPointerException x) |
|
53 { |
|
54 } |
|
55 harness.check (sci, null); |
|
56 |
|
57 sci = null; |
|
58 try |
|
59 { |
|
60 sci = new StringCharacterIterator (null, 0, 0, 0); |
|
61 } |
|
62 catch (NullPointerException x) |
|
63 { |
|
64 } |
|
65 harness.check (sci, null); |
|
66 |
|
67 sci = null; |
|
68 try |
|
69 { |
|
70 sci = new StringCharacterIterator (null, 0); |
|
71 } |
|
72 catch (NullPointerException x) |
|
73 { |
|
74 } |
|
75 harness.check (sci, null); |
|
76 |
|
77 sci = null; |
|
78 try |
|
79 { |
|
80 sci = new StringCharacterIterator (null, 0); |
|
81 } |
|
82 catch (NullPointerException x) |
|
83 { |
|
84 } |
|
85 harness.check (sci, null); |
|
86 |
|
87 sci = null; |
|
88 try |
|
89 { |
|
90 sci = new StringCharacterIterator ("ontology", -1); |
|
91 } |
|
92 catch (IllegalArgumentException x) |
|
93 { |
|
94 } |
|
95 harness.check (sci, null); |
|
96 |
|
97 sci = null; |
|
98 try |
|
99 { |
|
100 sci = new StringCharacterIterator ("ontology", 9); |
|
101 } |
|
102 catch (IllegalArgumentException x) |
|
103 { |
|
104 } |
|
105 harness.check (sci, null); |
|
106 |
|
107 sci = null; |
|
108 try |
|
109 { |
|
110 sci = new StringCharacterIterator ("ontology", -9, 0, 1); |
|
111 } |
|
112 catch (IllegalArgumentException x) |
|
113 { |
|
114 } |
|
115 harness.check (sci, null); |
|
116 |
|
117 sci = null; |
|
118 try |
|
119 { |
|
120 sci = new StringCharacterIterator ("ontology", 0, -5, 1); |
|
121 } |
|
122 catch (IllegalArgumentException x) |
|
123 { |
|
124 } |
|
125 harness.check (sci, null); |
|
126 |
|
127 sci = null; |
|
128 try |
|
129 { |
|
130 sci = new StringCharacterIterator ("ontology", 0, 1, -1); |
|
131 } |
|
132 catch (IllegalArgumentException x) |
|
133 { |
|
134 } |
|
135 harness.check (sci, null); |
|
136 |
|
137 sci = null; |
|
138 try |
|
139 { |
|
140 sci = new StringCharacterIterator ("ontology", 5, 2, 3); |
|
141 } |
|
142 catch (IllegalArgumentException x) |
|
143 { |
|
144 } |
|
145 harness.check (sci, null); |
|
146 |
|
147 sci = null; |
|
148 try |
|
149 { |
|
150 sci = new StringCharacterIterator ("ontology", 2, 5, 7); |
|
151 } |
|
152 catch (IllegalArgumentException x) |
|
153 { |
|
154 } |
|
155 harness.check (sci, null); |
|
156 |
|
157 // You could add a few more failure tests to be a bit more |
|
158 // complete, I suppose. Feel free to add more to regression |
|
159 // test your implementation. |
|
160 |
|
161 harness.checkPoint ("successful constructors"); |
|
162 |
|
163 sci = new StringCharacterIterator ("ontology"); |
|
164 harness.check (sci.getBeginIndex (), 0); |
|
165 harness.check (sci.getEndIndex (), 8); |
|
166 harness.check (sci.getIndex (), 0); |
|
167 |
|
168 sci = new StringCharacterIterator ("ontology", 5); |
|
169 harness.check (sci.getBeginIndex (), 0); |
|
170 harness.check (sci.getEndIndex (), 8); |
|
171 harness.check (sci.getIndex (), 5); |
|
172 |
|
173 sci = new StringCharacterIterator ("ontology", 0, 7, 3); |
|
174 harness.check (sci.getBeginIndex (), 0); |
|
175 harness.check (sci.getEndIndex (), 7); |
|
176 harness.check (sci.getIndex (), 3); |
|
177 |
|
178 harness.checkPoint ("clone"); |
|
179 StringCharacterIterator s2 = (StringCharacterIterator) sci.clone (); |
|
180 harness.check (s2.getBeginIndex (), 0); |
|
181 harness.check (s2.getEndIndex (), 7); |
|
182 harness.check (s2.getIndex (), 3); |
|
183 harness.check (sci.equals (s2)); |
|
184 } |
|
185 } |
|