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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
/* *******************************************************************
* Copyright (c) 1999-2001 Xerox Corporation,
* 2002 Palo Alto Research Center, Incorporated (PARC).
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Xerox/PARC initial implementation
* ******************************************************************/
package org.aspectj.testing.harness.bridge;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.aspectj.bridge.*;
import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.MessageUtil;
/**
* Primarily used by others to test AjcTest
*/
public class AjcSpecTest extends TestCase {
public static final String NOTSAME = " != ";
public static void sameAjcSuiteSpec(
AjcTest.Suite.Spec lhsSpec,
AjcTest.Suite.Spec rhsSpec,
Assert a) {
assertNotNull(lhsSpec);
assertNotNull(rhsSpec);
Iterator lhs = lhsSpec.getChildren().iterator();
Iterator rhs = rhsSpec.getChildren().iterator();
while (lhs.hasNext() && rhs.hasNext()) {
AjcTest.Spec lhsTest = (AjcTest.Spec) lhs.next();
AjcTest.Spec rhsTest = (AjcTest.Spec) rhs.next();
AjcSpecTest.sameAjcTestSpec(lhsTest, rhsTest, a);
}
assertTrue(!lhs.hasNext());
assertTrue(!rhs.hasNext());
}
public static void sameAjcTestSpec(
AjcTest.Spec lhsTest,
AjcTest.Spec rhsTest,
Assert a) {
assertNotNull(lhsTest);
assertNotNull(rhsTest);
assertEquals(lhsTest.getBugId(), rhsTest.getBugId());
assertEquals(lhsTest.getTestDirOffset(), rhsTest.getTestDirOffset());
// XXX suiteDir varies by run..
// description, options, paths, comments, keywords
sameAbstractRunSpec(lhsTest, rhsTest, a);
}
public static void sameAbstractRunSpec(
AbstractRunSpec lhs,
AbstractRunSpec rhs,
Assert a) {
assertEquals(lhs.description, rhs.description);
// XXX keywords added in .txt reading -
//sameList(lhs.getKeywordsList(), rhs.getKeywordsList(), a);
// XXX sameList(lhs.globalOptions, rhs.globalOptions, a);
sameList(lhs.getOptionsList(), rhs.getOptionsList(), a);
sameList(lhs.getPathsList(), rhs.getPathsList(), a);
assertEquals(lhs.isStaging(), rhs.isStaging());
sameList(lhs.keywords, rhs.keywords, a);
assertEquals(lhs.comment, rhs.comment);
assertEquals(lhs.badInput, rhs.badInput);
// xml adds sourceloc?
//sameSourceLocation(lhs.getSourceLocation(), rhs.getSourceLocation(), a);
// XXX also sourceLocations?
sameMessages(lhs.getMessages(), rhs.getMessages(), a);
}
/** @return normal form - null is "", "" is "", and others are {fully.qualified.class}.toString().trim() */
static String normal(Object input) {
if ((null == input) || ("".equals(input))) {
return "";
} else {
return input.getClass().getName() + "." + input.toString().trim();
}
}
/** @return true if these match after normalizing */
public static void same(Object lhs, Object rhs, Assert a) {
lhs = normal(lhs);
rhs = normal(rhs);
assertTrue(lhs + NOTSAME + rhs, lhs.equals(rhs));
}
/** @return true if both are empty (null or no entries) or if all match */
public static void sameRA(String[] lhs, String[] rhs, Assert a) {
if (null == lhs) {
assertTrue((null == rhs) || (0 == rhs.length));
} else if (null == rhs) {
assertTrue(0 == lhs.length);
} else {
String l = normal(lhs);
String r = normal(rhs);
assertTrue(l + NOTSAME + r, l.equals(r));
}
}
/** @return normal form for String[] items*/
static String normal(String[] items) {
return (null == items ? "[]" : normal(Arrays.asList(items)));
}
/** @return normal form for list items */
static String normal(List list) {
StringBuffer sb = new StringBuffer();
sb.append("[");
boolean first = true;
for (Iterator iter = list.iterator(); iter.hasNext();) {
Object o = iter.next();
if (!first) {
sb.append(", ");
} else {
first = false;
}
sb.append(normal(o));
}
sb.append("]");
return sb.toString();
}
/** @return true if both are empty (null or no entries) or if all match after trimming */
public static void sameListSize(List lhs, List rhs) {
if (null == lhs) {
assertTrue((null == rhs) || (0 == rhs.size()));
} else if (null == rhs) {
assertTrue(0 == lhs.size());
} else {
assertTrue(rhs.size() == lhs.size());
}
}
/** @return true if both are empty (null or no entries) or if all match after trimming */
public static void sameList(List lhs, List rhs, Assert a) {
sameListSize(lhs, rhs);
String l = normal(lhs);
String r = normal(rhs);
String label = l + NOTSAME + r;
assertTrue(label, l.equals(r));
}
// /**
// * Normalize and compare:
// * <li>bug id's are not compared since extracted during xml writing</li>
// * <li>keyword compare is disabled since keywords are generated during xml reading.</li>
// * <li>description compare is normalized by stripping bug ids</li>
// * <li>String and arrays are equal when empty (null or 0-length)</li>
// * @see Ajctest#stripBugId(String)
// */
// public static void sameAjcTest(AjcTest lhs, AjcTest rhs, Assert reporter) {
// Assert a = reporter;
// String label = lhs + NOTSAME + rhs;
// assertTrue(label, null != lhs);
// assertTrue(label, null != rhs);
// //assertTrue(label, lhs.ignoreWarnings == rhs.ignoreWarnings);
// // XXX disabled - not in .txt
// // sameStringList(lhs.keywords, rhs.keywords, a);
// // sameString(lhs.bugId, rhs.bugId, a);
// // argh - bugid stripped from description
// //same(AjcTest.stripBugId(lhs.description), AjcTest.stripBugId(lhs.description), a);
// //sameRA(lhs.globals, rhs.globals, a);
// //lhs.reset();
// //rhs.reset();
// boolean gotOne = false;
// IMessageHolder holder = new MessageHandler();
// assertTrue(label, !holder.hasAnyMessage(IMessage.FAIL, IMessageHolder.ORGREATER));
// while (lhs.hasNextRun() && rhs.hasNextRun()) {
// sameIAjcRun((IAjcRun) lhs.nextRun(holder), (IAjcRun) rhs.nextRun(holder), reporter);
// assertTrue(label, !holder.hasAnyMessage(IMessage.FAIL, IMessageHolder.ORGREATER));
// if (!gotOne) {
// gotOne = true;
// }
// }
// assertTrue(label, gotOne);
// assertTrue(label, !lhs.hasNextRun());
// assertTrue(label, !rhs.hasNextRun());
// }
public static void sameIAjcRun(IAjcRun lhs, IAjcRun rhs, Assert reporter) {
// Assert a = reporter;
assertTrue(lhs != null);
assertTrue(rhs != null);
Class c = lhs.getClass();
assertTrue(c == rhs.getClass());
AbstractRunSpec lhsSpec;
AbstractRunSpec rhsSpec;
if (c == CompilerRun.class) {
CompilerRun.Spec l = ((CompilerRun) lhs).spec;
CompilerRun.Spec r = ((CompilerRun) rhs).spec;
lhsSpec = l;
rhsSpec = r;
assertEquals(l.argfiles, r.argfiles);
assertEquals(l.aspectpath, r.aspectpath);
assertEquals(l.testSrcDirOffset, r.testSrcDirOffset);
assertEquals(l.compiler, r.compiler);
assertEquals(l.includeClassesDir, r.includeClassesDir);
assertEquals(l.reuseCompiler, r.reuseCompiler);
assertEquals(l.sourceroots, r.sourceroots);
assertEquals(l.extdirs, r.extdirs);
} else if (c == JavaRun.class) {
JavaRun.Spec l = ((JavaRun) lhs).spec;
JavaRun.Spec r = ((JavaRun) rhs).spec;
lhsSpec = l;
rhsSpec = r;
assertTrue(l.skipTester == r.skipTester);
assertEquals(l.className, r.className);
assertEquals(l.javaVersion, r.javaVersion);
assertEquals(l.skipTester, r.skipTester);
assertEquals(l.outStreamIsError, r.outStreamIsError);
assertEquals(l.errStreamIsError, r.errStreamIsError);
} else if (c == IncCompilerRun.class) {
IncCompilerRun.Spec l = ((IncCompilerRun) lhs).spec;
IncCompilerRun.Spec r = ((IncCompilerRun) rhs).spec;
lhsSpec = l;
rhsSpec = r;
assertEquals(l.tag, r.tag);
assertEquals(l.fresh, r.fresh);
} else {
assertTrue(lhs.equals(rhs));
return;
}
sameSpec(lhsSpec, rhsSpec, reporter);
}
public static void sameSpec(AbstractRunSpec lhs, AbstractRunSpec rhs, Assert a) {
if ((null == lhs) && (null == rhs)) {
return;
}
assertTrue(lhs != null);
assertTrue(rhs != null);
assertEquals(""+lhs.getOptionsList(), ""+rhs.getOptionsList());
sameList(lhs.getPathsList(), rhs.getPathsList(), a);
sameMessages(lhs.getMessages(), rhs.getMessages(), a);
sameDirChangesList(lhs.dirChanges, rhs.dirChanges, a);
}
public static void sameDirChangesList(ArrayList lhs, ArrayList rhs, Assert a) {
if ((null == lhs) && (null == rhs)) {
return;
}
assertTrue(rhs != null);
assertTrue(lhs != null);
sameListSize(lhs, rhs);
Iterator lhsIter = lhs.iterator();
Iterator rhsIter = rhs.iterator();
while (lhsIter.hasNext() && rhsIter.hasNext()) {
sameDirChangesSpec((DirChanges.Spec) lhsIter.next(), (DirChanges.Spec) rhsIter.next(), a);
}
}
public static void sameDirChangesSpec(DirChanges.Spec lhs, DirChanges.Spec rhs, Assert a) {
if ((null == lhs) && (null == rhs)) {
return;
}
assertTrue(rhs != null);
assertTrue(lhs != null);
assertEquals(lhs.defaultSuffix, rhs.defaultSuffix);
assertEquals(lhs.dirToken, rhs.dirToken);
assertEquals(lhs.fastFail, rhs.fastFail);
assertEquals(lhs.expDir, rhs.expDir); // XXX normalize?
sameList(lhs.updated, rhs.updated, a);
sameList(lhs.removed, rhs.removed, a);
sameList(lhs.added, rhs.added, a);
}
public static void sameMessages(IMessageHolder one, IMessageHolder two, Assert a) {
if ((null == one) && (null == two)) {
return;
}
// order matters here
ListIterator lhs = one.getUnmodifiableListView().listIterator();
ListIterator rhs = two.getUnmodifiableListView().listIterator();
while (lhs.hasNext() && rhs.hasNext()) {
sameMessage((IMessage) lhs.next(), (IMessage) rhs.next(), a);
}
assertTrue(!lhs.hasNext());
assertTrue(!rhs.hasNext());
}
public static void sameMessage(IMessage lhs, IMessage rhs, Assert a) {
if ((null == lhs) && (null == rhs)) {
return;
}
assertTrue(lhs != null);
assertTrue(rhs != null);
assertTrue(lhs.getKind() == rhs.getKind());
same(lhs.getMessage(), rhs.getMessage(), a);
same(lhs.getDetails(), rhs.getDetails(), a);
assertEquals(lhs.getThrown(), rhs.getThrown());
sameSourceLocation(lhs.getSourceLocation(), rhs.getSourceLocation());
sameSourceLocations(lhs.getExtraSourceLocations(), rhs.getExtraSourceLocations());
}
public static void sameSourceLocations(List lhs, List rhs) {
sameListSize(lhs, rhs);
if ((null == lhs) || (0 == lhs.size())) {
return;
}
// ok, do order-dependent check..
ListIterator iterLeft = lhs.listIterator();
ListIterator iterRight = rhs.listIterator();
while (iterLeft.hasNext() && iterRight.hasNext()) {
ISourceLocation left = (ISourceLocation) iterLeft.next();
ISourceLocation right = (ISourceLocation) iterRight.next();
sameSourceLocation(left, right);
}
assertTrue(!iterLeft.hasNext());
assertTrue(!iterRight.hasNext());
}
public static void sameSourceLocation(ISourceLocation lhs, ISourceLocation rhs) {
if ((null == lhs) && (null == rhs)) {
return;
}
assertTrue(lhs != null);
assertTrue(rhs != null);
assertTrue(lhs.getLine() == rhs.getLine());
assertTrue(lhs.getColumn() == rhs.getColumn());
assertTrue(lhs.getOffset() == rhs.getOffset());
assertTrue(lhs.getEndLine() == rhs.getEndLine());
// XXX need to compare files, permitting null == NONE
}
/**
* Constructor for AjcSpecTest.
* @param name
*/
public AjcSpecTest(String name) {
super(name);
}
public void testMinimal() {
AjcTest.Spec one = new AjcTest.Spec();
AjcTest.Spec two = new AjcTest.Spec();
// empty/identity tests
sameAjcTestSpec(one, two, this);
one.addOption("-one");
one.addKeyword("keyword");
one.addPath("path");
IMessage m = MessageUtil.info("info message");
one.addMessage(m);
DirChanges.Spec dcspec = new DirChanges.Spec();
dcspec.setDirToken("dirToken");
dcspec.setDefaultSuffix(".suffix");
one.addDirChanges(dcspec);
// full/identity tests
sameAjcTestSpec(one, one, this);
// XXX need to clone...
// XXX need to test that more differences are detected
boolean passed = false;
try {
sameAjcTestSpec(one, two, this);
} catch (AssertionFailedError e) {
passed = true;
}
assertTrue("did not get expected exception", passed);
}
}
|