1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 package com.gargoylesoftware.base.gui;
39
40 import com.gargoylesoftware.base.util.DetailedIllegalArgumentException;
41 import com.gargoylesoftware.base.util.DetailedNullPointerException;
42 import junit.framework.TestCase;
43
44 /***
45 * Tests for TableLayoutConstraints
46 *
47 * @version $Revision: 1.6 $
48 * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
49 */
50 public class TableLayoutConstraintsTest extends TestCase {
51
52 /***
53 * Create a new test case.
54 * @param name The name of the test.
55 */
56 public TableLayoutConstraintsTest( final String name ) {
57 super(name);
58 }
59
60 /***
61 * Test the constuctor with legal values.
62 */
63 public void testConstructor2Parms() {
64 final TableLayoutConstraints constraints
65 = new TableLayoutConstraints(1,2);
66
67 assertEquals("row", constraints.getRow(), 1 );
68 assertEquals("column", constraints.getColumn(),2);
69 assertEquals("rowSpan", constraints.getRowSpan(), 1);
70 assertEquals("columnSpan", constraints.getColumnSpan(), 1 );
71
72 assertEquals("verticalAlignment",
73 constraints.getVerticalAlignment(),
74 TableLayout.CENTER );
75 assertTrue("verticalStretch",
76 constraints.getVerticalStretch() == false );
77
78 assertEquals("horizontalAlignment",
79 constraints.getHorizontalAlignment(),
80 TableLayout.LEFT );
81 assertTrue("horizontalStretch",
82 constraints.getHorizontalStretch() == false );
83 }
84
85 /***
86 * Test the constructor will negative parameters.
87 */
88 public void testConstructor2Parms_Negative() {
89 try {
90 new TableLayoutConstraints(-1,2);
91 fail("Expected exception for negative row");
92 }
93 catch( final IllegalArgumentException e ) {
94
95 }
96
97 try {
98 new TableLayoutConstraints(1,-2);
99 fail("Expected exception for negative column");
100 }
101 catch( final IllegalArgumentException e ) {
102
103 }
104 }
105
106 /***
107 * Test a negative row.
108 */
109 public void testNegativeRow() {
110 try {
111 new TableLayoutConstraints(-1,2);
112 fail("Expected IllegalArgumentException");
113 }
114 catch( final IllegalArgumentException e ) {
115
116 }
117 }
118
119 /***
120 * Test a negative row span
121 */
122 public void testNegativeRowSpan() {
123 final TableLayoutConstraints constraints = new TableLayoutConstraints(1,2);
124 try {
125 constraints.setRowSpan(-1);
126 fail("Expected IllegalArgumentException");
127 }
128 catch( final IllegalArgumentException e ) {
129
130 }
131 }
132
133 /***
134 * Test a zero row span.
135 */
136 public void testZeroRowSpan() {
137 final TableLayoutConstraints constraints = new TableLayoutConstraints(1,2);
138 try {
139 constraints.setRowSpan(0);
140 fail("Expected IllegalArgumentException");
141 }
142 catch( final IllegalArgumentException e ) {
143
144 }
145 }
146
147 /***
148 * Test a negative column.
149 */
150 public void testNegativeColumn() {
151 try {
152 new TableLayoutConstraints(1,-2);
153 fail("Expected IllegalArgumentException");
154 }
155 catch( final IllegalArgumentException e ) {
156
157 }
158 }
159
160 /***
161 * Test a negative column span.
162 */
163 public void testNegativeColumnSpan() {
164 final TableLayoutConstraints constraints = new TableLayoutConstraints(1,2);
165 try {
166 constraints.setColumnSpan(-4);
167 fail("Expected IllegalArgumentException");
168 }
169 catch( final IllegalArgumentException e ) {
170
171 }
172 }
173
174 /***
175 * Test a zero column span
176 */
177 public void testZeroColumnSpan() {
178 final TableLayoutConstraints constraints = new TableLayoutConstraints(1,2);
179 try {
180 constraints.setColumnSpan(0);
181 fail("Expected IllegalArgumentException");
182 }
183 catch( final IllegalArgumentException e ) {
184
185 }
186 }
187
188 /***
189 * Test an illegal vertical alignment.
190 */
191 public void testIllegalVerticalAlignment() {
192 final TableLayoutConstraints constraints = new TableLayoutConstraints(1,2);
193 try {
194 constraints.setVerticalAlignment(TableLayout.RIGHT);
195 fail("Expected IllegalArgumentException");
196 }
197 catch( final IllegalArgumentException e ) {
198
199 }
200 }
201
202 /***
203 * Test an illegal horizontal alignment.
204 */
205 public void testIllegalHorizontalAlignment() {
206 final TableLayoutConstraints constraints = new TableLayoutConstraints(1,2);
207 try {
208 constraints.setHorizontalAlignment(TableLayout.TOP);
209 fail("Expected IllegalArgumentException");
210 }
211 catch( final IllegalArgumentException e ) {
212
213 }
214 }
215
216
217 /***
218 * Test makeConstraints() with bad input.
219 */
220 public void testMakeConstraints_BadData() {
221 final String data[] = {
222 "", ","
223 };
224
225 int i;
226 for( i=0; i<data.length; i++ ) {
227 try {
228 TableLayoutConstraints.makeConstraints(data[i]);
229 fail("Expected exception for ["+data[i]+"]");
230 }
231 catch( final DetailedIllegalArgumentException e ) {
232 assertEquals(e.getMessage(), "constraintString", e.getArgumentName());
233 }
234 }
235 }
236
237
238 /***
239 * Test makeConstraints() with bad input.
240 */
241 public void testMakeConstraints_Null() {
242
243 try {
244 TableLayoutConstraints.makeConstraints(null);
245 fail("Expected exception for null");
246 }
247 catch( final DetailedNullPointerException e ) {
248 assertEquals("constraintString", e.getArgumentName());
249 }
250 }
251
252
253 /***
254 * Test makeConstraints with legal input.
255 */
256 public void testMakeConstraints() {
257 final TableLayoutConstraints constraints
258 = TableLayoutConstraints.makeConstraints("5,17");
259 assertEquals("row", 5, constraints.getRow() );
260 assertEquals("column", 17, constraints.getColumn() );
261 }
262
263 /***
264 * Test make constraints with spanning.
265 */
266 public void testMakeConstraints_spanning() {
267 final TableLayoutConstraints constraints
268 = TableLayoutConstraints.makeConstraints("5+2,7+3");
269 assertEquals("row", 5, constraints.getRow() );
270 assertEquals("column", 7, constraints.getColumn() );
271 assertEquals("rowSpan", 2, constraints.getRowSpan() );
272 assertEquals("columnSpan", 3, constraints.getColumnSpan() );
273
274 if( constraints.getVerticalStretch() == true ) {
275 fail("Not expecting vertical stretch");
276 }
277 if( constraints.getHorizontalStretch() == true ) {
278 fail("Not expecting horizontal stretch");
279 }
280 }
281
282 /***
283 * Test makeConstraints() with stretching.
284 */
285 public void testMakeConstraints_stretching() {
286 final TableLayoutConstraints constraints
287 = TableLayoutConstraints.makeConstraints("5s,7+3s");
288 assertEquals("row", 5, constraints.getRow() );
289 assertEquals("column", 7, constraints.getColumn() );
290 assertEquals("columnSpan", 3, constraints.getColumnSpan() );
291
292 if( constraints.getVerticalStretch() == false ) {
293 fail("Expected vertical stretch");
294 }
295 if( constraints.getHorizontalStretch() == false ) {
296 fail("Expected horizontal stretch");
297 }
298 }
299
300 }