aboutsummaryrefslogtreecommitdiffstats
path: root/testing/testsrc/org/aspectj
diff options
context:
space:
mode:
authorwisberg <wisberg>2002-12-16 18:14:27 +0000
committerwisberg <wisberg>2002-12-16 18:14:27 +0000
commit1025cde05abe95be6ca65aab3ba126258efc647f (patch)
tree7d40d6fa06fef869e4d38cbe44ce431011e2eff8 /testing/testsrc/org/aspectj
parentd842c4f1139629c1f062b74ba818d233b2c31043 (diff)
downloadaspectj-1025cde05abe95be6ca65aab3ba126258efc647f.tar.gz
aspectj-1025cde05abe95be6ca65aab3ba126258efc647f.zip
initial version
Diffstat (limited to 'testing/testsrc/org/aspectj')
-rw-r--r--testing/testsrc/org/aspectj/testing/harness/bridge/AbstractRunSpecTest.java65
-rw-r--r--testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java340
-rw-r--r--testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunSpecTest.java163
-rw-r--r--testing/testsrc/org/aspectj/testing/harness/bridge/ParseTestCase.java228
-rw-r--r--testing/testsrc/org/aspectj/testing/harness/bridge/TestingBridgeTests.java32
-rw-r--r--testing/testsrc/org/aspectj/testing/util/BridgeUtilTest.java100
-rw-r--r--testing/testsrc/org/aspectj/testing/util/FileUtilTest.java46
-rw-r--r--testing/testsrc/org/aspectj/testing/util/IteratorWrapperTest.java164
-rw-r--r--testing/testsrc/org/aspectj/testing/util/LangUtilTest.java342
-rw-r--r--testing/testsrc/org/aspectj/testing/util/MessageUtilTest.java130
-rw-r--r--testing/testsrc/org/aspectj/testing/util/StreamGrabberTest.java112
-rw-r--r--testing/testsrc/org/aspectj/testing/util/TestDiffsTest.java114
-rw-r--r--testing/testsrc/org/aspectj/testing/util/UtilTests.java36
-rw-r--r--testing/testsrc/org/aspectj/testing/xml/AjcSpecXmlReaderTest.java236
-rw-r--r--testing/testsrc/org/aspectj/testing/xml/TestingXmlTests.java31
-rw-r--r--testing/testsrc/org/aspectj/testing/xml/XMLWriterTest.java44
16 files changed, 2183 insertions, 0 deletions
diff --git a/testing/testsrc/org/aspectj/testing/harness/bridge/AbstractRunSpecTest.java b/testing/testsrc/org/aspectj/testing/harness/bridge/AbstractRunSpecTest.java
new file mode 100644
index 000000000..0e5b8651f
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/harness/bridge/AbstractRunSpecTest.java
@@ -0,0 +1,65 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+package org.aspectj.testing.harness.bridge;
+
+import org.aspectj.testing.run.IRunIterator;
+import org.aspectj.testing.xml.XMLWriter;
+
+import java.io.PrintWriter;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class AbstractRunSpecTest extends TestCase {
+
+ public AbstractRunSpecTest(String name) {
+ super(name);
+ }
+
+ public void skiptestXmlWrite() {
+ AbstractRunSpec spec = new TestSpec();
+ spec.setOptions("-option1,-option2");
+ spec.setKeywords("keyword1, keyword2");
+ spec.setPaths("path1.java, path2.java");
+ spec.setDescription("some description, with extra");
+ XMLWriter out = new XMLWriter(new PrintWriter(System.out));
+ spec.writeXml(out);
+ out.close();
+ }
+
+ public void testSetOptions() {
+ AbstractRunSpec spec = new TestSpec();
+ spec.setOptions("1,2");
+ List options = spec.getOptionsList();
+ String s = "" + options;
+ assertTrue(s, "[1, 2]".equals(s));
+ }
+
+ static class TestSpec extends AbstractRunSpec {
+ TestSpec() {
+ super("testspec");
+ }
+ /**
+ * @see org.aspectj.testing.harness.bridge.AbstractRunSpec#makeRunIterator(Sandbox, Validator)
+ */
+ public IRunIterator makeRunIterator(
+ Sandbox sandbox,
+ Validator validator) {
+ return null;
+ }
+ }
+}
diff --git a/testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java b/testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java
new file mode 100644
index 000000000..635790158
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java
@@ -0,0 +1,340 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+package org.aspectj.testing.harness.bridge;
+
+import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.IMessageHolder;
+import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.bridge.MessageHandler;
+import org.aspectj.bridge.MessageUtil;
+import org.aspectj.testing.harness.bridge.AjcTest.Suite.Spec;
+import org.aspectj.testing.xml.AjcSpecXmlReaderTest;
+
+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;
+
+/**
+ * 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);
+ }
+ a.assertTrue(!lhs.hasNext());
+ a.assertTrue(!rhs.hasNext());
+ }
+
+ public static void sameAjcTestSpec(
+ AjcTest.Spec lhsTest,
+ AjcTest.Spec rhsTest,
+ Assert a) {
+ a.assertNotNull(lhsTest);
+ a.assertNotNull(rhsTest);
+ a.assertEquals(lhsTest.getBugId(), rhsTest.getBugId());
+ a.assertEquals(lhsTest.getTestDirOffset(), rhsTest.getTestDirOffset());
+ // XXX suiteDir varies by run..
+ sameAbstractRunSpec(lhsTest, rhsTest, a);
+ }
+
+ public static void sameAbstractRunSpec(
+ AbstractRunSpec lhs,
+ AbstractRunSpec rhs,
+ Assert a) {
+ 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);
+ // 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);
+ a.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) {
+ a.assertTrue((null == rhs) || (0 == rhs.length));
+ } else if (null == rhs) {
+ a.assertTrue(0 == lhs.length);
+ } else {
+ String l = normal(lhs);
+ String r = normal(rhs);
+ a.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, Assert a) {
+ if (null == lhs) {
+ a.assertTrue((null == rhs) || (0 == rhs.size()));
+ } else if (null == rhs) {
+ a.assertTrue(0 == lhs.size());
+ } else {
+ a.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, a);
+ String l = normal(lhs);
+ String r = normal(rhs);
+ String label = l + NOTSAME + r;
+ a.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;
+// a.assertTrue(label, null != lhs);
+// a.assertTrue(label, null != rhs);
+// //a.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();
+// a.assertTrue(label, !holder.hasAnyMessage(IMessage.FAIL, IMessageHolder.ORGREATER));
+// while (lhs.hasNextRun() && rhs.hasNextRun()) {
+// sameIAjcRun((IAjcRun) lhs.nextRun(holder), (IAjcRun) rhs.nextRun(holder), reporter);
+// a.assertTrue(label, !holder.hasAnyMessage(IMessage.FAIL, IMessageHolder.ORGREATER));
+// if (!gotOne) {
+// gotOne = true;
+// }
+// }
+// a.assertTrue(label, gotOne);
+// a.assertTrue(label, !lhs.hasNextRun());
+// a.assertTrue(label, !rhs.hasNextRun());
+// }
+
+ public static void sameIAjcRun(IAjcRun lhs, IAjcRun rhs, Assert reporter) {
+ Assert a = reporter;
+ a.assertTrue(lhs != null);
+ a.assertTrue(rhs != null);
+ Class c = lhs.getClass();
+ a.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;
+ a.assertEquals(l.testSrcDirOffset, r.testSrcDirOffset);
+ a.assertEquals(l.compiler, r.compiler);
+ } else if (c == JavaRun.class) {
+ JavaRun.Spec l = ((JavaRun) lhs).spec;
+ JavaRun.Spec r = ((JavaRun) rhs).spec;
+ lhsSpec = l;
+ rhsSpec = r;
+ a.assertTrue(l.skipTester == r.skipTester);
+ a.assertEquals(l.className, r.className);
+ } else if (c == IncCompilerRun.class) {
+ IncCompilerRun.Spec l = ((IncCompilerRun) lhs).spec;
+ IncCompilerRun.Spec r = ((IncCompilerRun) rhs).spec;
+ lhsSpec = l;
+ rhsSpec = r;
+ } 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;
+ }
+ a.assertTrue(lhs != null);
+ a.assertTrue(rhs != null);
+ a.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;
+ }
+ a.assertTrue(rhs != null);
+ a.assertTrue(lhs != null);
+ sameListSize(lhs, rhs, a);
+ 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;
+ }
+ a.assertTrue(rhs != null);
+ a.assertTrue(lhs != null);
+ a.assertEquals(lhs.defaultSuffix, rhs.defaultSuffix);
+ a.assertEquals(lhs.dirToken, rhs.dirToken);
+ sameList(lhs.updated, rhs.updated, a);
+ sameList(lhs.removed, rhs.removed, a);
+ sameList(lhs.added, rhs.added, a);
+ }
+
+ public static void sameMessages(List one, List two, Assert a) {
+ if ((null == one) && (null == two)) {
+ return;
+ }
+ Iterator lhs = one.iterator();
+ Iterator rhs = two.iterator();
+ 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;
+ }
+ a.assertTrue(lhs != null);
+ a.assertTrue(rhs != null);
+ a.assertTrue(lhs.getKind() == rhs.getKind());
+ same(lhs.getMessage(), rhs.getMessage(), a);
+ a.assertEquals(lhs.getThrown(), rhs.getThrown());
+ sameSourceLocation(lhs.getISourceLocation(), rhs.getISourceLocation(), a);
+ }
+
+ public static void sameSourceLocation(ISourceLocation lhs, ISourceLocation rhs, Assert a) {
+ if ((null == lhs) && (null == rhs)) {
+ return;
+ }
+ a.assertTrue(lhs != null);
+ a.assertTrue(rhs != null);
+ a.assertTrue(lhs.getLine() == rhs.getLine());
+ a.assertTrue(lhs.getColumn() == rhs.getColumn());
+ a.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);
+ }
+}
diff --git a/testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunSpecTest.java b/testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunSpecTest.java
new file mode 100644
index 000000000..ddd908b33
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/harness/bridge/CompilerRunSpecTest.java
@@ -0,0 +1,163 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+package org.aspectj.testing.harness.bridge;
+
+import org.aspectj.bridge.MessageHandler;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class CompilerRunSpecTest extends TestCase {
+
+ /**
+ * Constructor for CompilerRunSpecTest.
+ * @param name
+ */
+ public CompilerRunSpecTest(String name) {
+ super(name);
+ }
+
+ public void testSetupArgs() {
+ checkSetupArgs("verbose", false);
+ checkSetupArgs("lenient", false);
+ checkSetupArgs("strict", false);
+ checkSetupArgs("ajc", true); // XXX need to predict/test compiler selection
+ checkSetupArgs("eclipse", true);
+ }
+
+ void checkSetupArgs(String arg, boolean isTestArg) {
+ MessageHandler handler = new MessageHandler();
+ CompilerRun.Spec spec = new CompilerRun.Spec();
+ AbstractRunSpec.RT parentRuntime = new AbstractRunSpec.RT();
+ String result;
+ String expResult;
+
+ // -------- local set
+ // global ^ (force-off) to disable
+ spec.setOptions("-" + arg);
+ parentRuntime.setOptions(new String[] {"^" + arg});
+ assertTrue(spec.adoptParentValues(parentRuntime, handler));
+ if (0 != handler.numMessages(null, true)) {
+ assertTrue(handler.toString(), false);
+ }
+ result = ""+spec.testSetup.commandOptions;
+ assertTrue(result, "[]".equals(result));
+
+ // global ! (force-on) does not change local-set
+ parentRuntime.setOptions(new String[] {"!" + arg});
+ assertTrue(spec.adoptParentValues(parentRuntime, handler));
+ if (0 != handler.numMessages(null, true)) {
+ assertTrue(handler.toString(), false);
+ }
+ result = ""+spec.testSetup.commandOptions;
+ expResult = (isTestArg ? "[]" : "[-" + arg + "]");
+ assertTrue(result, expResult.equals(result));
+
+ // global - (set) does not change local-set
+ parentRuntime.setOptions(new String[] {"-" + arg});
+ assertTrue(spec.adoptParentValues(parentRuntime, handler));
+ if (0 != handler.numMessages(null, true)) {
+ assertTrue(handler.toString(), false);
+ }
+ result = ""+spec.testSetup.commandOptions;
+ expResult = (isTestArg ? "[]" : "[-" + arg + "]");
+ assertTrue(result, expResult.equals(result));
+
+ // global (unset) does not change local-set
+ parentRuntime.setOptions(new String[] {""});
+ assertTrue(spec.adoptParentValues(parentRuntime, handler));
+ if (0 != handler.numMessages(null, true)) {
+ assertTrue(handler.toString(), false);
+ }
+ result = ""+spec.testSetup.commandOptions;
+ expResult = (isTestArg ? "[]" : "[-" + arg + "]");
+ assertTrue(result, expResult.equals(result));
+
+ // -------- local force-on
+ // global ^ (force-off) conflicts with local force-on
+ spec.setOptions("!" + arg);
+ parentRuntime.setOptions(new String[] {"^" + arg});
+ assertTrue(!spec.adoptParentValues(parentRuntime, handler));
+ assertTrue(0 != handler.numMessages(null, true));
+ handler.init();
+
+ // global ! (force-on) does not change local force-on
+ parentRuntime.setOptions(new String[] {"!" + arg});
+ assertTrue(spec.adoptParentValues(parentRuntime, handler));
+ if (0 != handler.numMessages(null, true)) {
+ assertTrue(handler.toString(), false);
+ }
+ result = ""+spec.testSetup.commandOptions;
+ expResult = (isTestArg ? "[]" : "[-" + arg + "]");
+ assertTrue(result, expResult.equals(result));
+
+ // global - (set) does not change local force-on
+ parentRuntime.setOptions(new String[] {"-" + arg});
+ assertTrue(spec.adoptParentValues(parentRuntime, handler));
+ if (0 != handler.numMessages(null, true)) {
+ assertTrue(handler.toString(), false);
+ }
+ result = ""+spec.testSetup.commandOptions;
+ expResult = (isTestArg ? "[]" : "[-" + arg + "]");
+ assertTrue(result, expResult.equals(result));
+
+ // global (unset) does not change local force-on
+ parentRuntime.setOptions(new String[] {""});
+ assertTrue(spec.adoptParentValues(parentRuntime, handler));
+ if (0 != handler.numMessages(null, true)) {
+ assertTrue(handler.toString(), false);
+ }
+ result = ""+spec.testSetup.commandOptions;
+ expResult = (isTestArg ? "[]" : "[-" + arg + "]");
+ assertTrue(result, expResult.equals(result));
+
+
+ // -------- local force-off
+ // global ^ (force-off) does not change local force-off
+ spec.setOptions("^" + arg);
+ parentRuntime.setOptions(new String[] {"^" + arg});
+ assertTrue(spec.adoptParentValues(parentRuntime, handler));
+ if (0 != handler.numMessages(null, true)) {
+ assertTrue(handler.toString(), false);
+ }
+ result = ""+spec.testSetup.commandOptions;
+ assertTrue(result, ("[]").equals(result));
+
+ // global ! (force-on) conflicts with local force-off
+ parentRuntime.setOptions(new String[] {"!" + arg});
+ assertTrue(!spec.adoptParentValues(parentRuntime, handler));
+ assertTrue(0 != handler.numMessages(null, true));
+ handler.init();
+
+ // global - (set) overridden by local force-off // XXX??
+ parentRuntime.setOptions(new String[] {"-" + arg});
+ assertTrue(spec.adoptParentValues(parentRuntime, handler));
+ if (0 != handler.numMessages(null, true)) {
+ assertTrue(handler.toString(), false);
+ }
+ result = ""+spec.testSetup.commandOptions;
+ assertTrue(result, ("[]").equals(result));
+
+ // global (unset) does not change local force-off
+ parentRuntime.setOptions(new String[] {""});
+ assertTrue(spec.adoptParentValues(parentRuntime, handler));
+ if (0 != handler.numMessages(null, true)) {
+ assertTrue(handler.toString(), false);
+ }
+ result = ""+spec.testSetup.commandOptions;
+ assertTrue(result, ("[]").equals(result));
+ }
+}
diff --git a/testing/testsrc/org/aspectj/testing/harness/bridge/ParseTestCase.java b/testing/testsrc/org/aspectj/testing/harness/bridge/ParseTestCase.java
new file mode 100644
index 000000000..c8a708e13
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/harness/bridge/ParseTestCase.java
@@ -0,0 +1,228 @@
+/* *******************************************************************
+ * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+package org.aspectj.testing.harness.bridge;
+
+import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.IMessageHandler;
+import org.aspectj.bridge.IMessageHolder;
+import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.bridge.Message;
+import org.aspectj.bridge.MessageHandler;
+import org.aspectj.bridge.MessageUtil;
+import org.aspectj.bridge.SourceLocation;
+import org.aspectj.testing.run.IRun;
+import org.aspectj.testing.run.IRunIterator;
+import org.aspectj.testing.run.IRunListener;
+import org.aspectj.testing.run.IRunStatus;
+import org.aspectj.testing.run.IRunValidator;
+import org.aspectj.testing.run.RunStatus;
+import org.aspectj.testing.run.RunValidator;
+import org.aspectj.testing.run.Runner;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import junit.framework.TestCase;
+
+public class ParseTestCase extends TestCase {
+
+ public ParseTestCase(String name) {
+ super(name);
+ }
+
+
+ public void testParse() throws Exception { // XXX failing b/c of iteration
+ Runner runner = new Runner();
+ IMessageHolder handler = new MessageHandler();
+ RunStatus status;
+ Validator validator = new Validator(handler);
+ final File suiteFile = new File("../testing/testdata/suite.xml");
+ List tests = parseSuite(suiteFile);
+ Sandbox sandbox = new Sandbox(new File("testdata"), validator);
+ IRunListener listenerNULL = null;
+ ISourceLocation sl = new SourceLocation(suiteFile, 0, 0,0);
+ for (Iterator iter = tests.iterator(); iter.hasNext();) {
+ status = new RunStatus(handler, runner);
+ AjcTest.Spec test = (AjcTest.Spec) iter.next();
+ test.setSourceLocation(sl);
+ IRunIterator child = test.makeRunIterator(sandbox, validator);
+ //test.setup(new String[0], validator); // XXX
+ //IRun child = runner.wrap(test, null);
+ // huh? runIterator not generating child status?
+ //RunStatus childStatus = runner.makeChildStatus();
+ runner.runIterator(child, status, listenerNULL);
+ MessageUtil.print(System.err, status);
+ }
+ }
+
+ private List parseSuite(File file) throws ParserConfigurationException, IOException, SAXException{
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(true);
+ factory.setIgnoringElementContentWhitespace(true);
+ factory.setIgnoringComments(true);
+
+
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ System.out.println(file.getAbsoluteFile());
+ Document doc = builder.parse(file);
+
+ dump(doc.getDocumentElement(), 0);
+
+ List ret = new ArrayList();
+ Node suiteNode = doc.getDocumentElement();
+
+ NodeList children = suiteNode.getChildNodes();
+ for (int i=0; i < children.getLength(); i++) {
+ ret.add(parseTest(children.item(i)));
+ }
+
+ return ret;
+ }
+
+ private AjcTest.Spec parseTest(Node node) {
+ String title = getAttributeString(node, "title");
+ String pr = getAttributeString(node, "pr");
+ String dir = getAttributeString(node, "dir");
+
+ ISourceLocation sourceLocation =
+ new SourceLocation(new File("Missing"), 0, 0, 0);
+ AjcTest.Spec test = new AjcTest.Spec();
+ test.setDescription(title);
+ test.setTestDirOffset(dir);
+ test.setBugId(Integer.valueOf(pr).intValue());
+ test.setSourceLocation(sourceLocation);
+ //AjcTest test = new AjcTest(title, dir, pr, sourceLocation);
+
+ System.out.println(test);
+
+ List ret = new ArrayList();
+
+ NodeList children = node.getChildNodes();
+ for (int i=0; i < children.getLength(); i++) {
+ test.addChild(parseIRun(test, children.item(i), dir));
+// test.addRunSpec(parseIRun(test, children.item(i), dir));
+ }
+
+ return test;
+ }
+
+ private IRunSpec parseIRun(AjcTest.Spec test, Node node, String baseDir) {
+ String kind = node.getNodeName();
+ if (kind.equals("compile")) {
+ List args = parseChildrenStrings(node, "arg");
+ List files = parseChildrenStrings(node, "file");
+ List expectedMessages = parseChildrenMessages(node);
+ CompilerRun.Spec spec = new CompilerRun.Spec();
+ spec.addOptions((String[]) args.toArray(new String[0]));
+ spec.addPaths((String[]) args.toArray(new String[0]));
+ spec.addMessages(expectedMessages);
+ spec.testSrcDirOffset = null; // baseDir;
+ return spec;
+ } else if (kind.equals("run")) {
+ JavaRun.Spec spec = new JavaRun.Spec();
+ spec.className = getAttributeString(node, "class");
+ spec.addOptions(new String[0]); //??? could add support here
+ JavaRun run = new JavaRun(spec);
+ return spec;
+ }
+
+ return null;
+ }
+
+ private List parseChildrenMessages(Node node) {
+ List ret = new ArrayList();
+
+ NodeList children = node.getChildNodes();
+ for (int i=0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ if (child.getNodeName().equals("message")) {
+ ret.add(parseMessage(child));
+ }
+ }
+ return ret;
+ }
+
+ private IMessage parseMessage(Node child) {
+ IMessage.Kind kind;
+ String sKind = getAttributeString(child, "kind");
+ if (sKind.equals("error")) { kind = IMessage.ERROR; }
+ else if (sKind.equals("warning")) { kind = IMessage.WARNING; }
+ else {
+ throw new RuntimeException("unknown kind: " + sKind);
+ }
+ String filename = getAttributeString(child, "file");
+ File file;
+ if (filename != null) {
+ file = new File(filename);
+ } else {
+ file = new File("XXX"); //XXX
+ }
+
+ int line = Integer.valueOf(getAttributeString(child, "line")).intValue();
+
+ ISourceLocation sourceLocation = new SourceLocation(file, line, line, 0);
+
+ return new Message("", kind, null, sourceLocation);
+ }
+
+
+
+ private List parseChildrenStrings(Node node, String kind) {
+ List ret = new ArrayList();
+
+ NodeList children = node.getChildNodes();
+ for (int i=0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ if (child.getNodeName().equals(kind)) {
+ Node first = child.getFirstChild();
+ if (null != first) {
+ ret.add(first.getNodeValue());// XXX
+ }
+ }
+ }
+ return ret;
+ }
+
+
+
+ private String getAttributeString(Node node, String name) {
+ Node attrNode = node.getAttributes().getNamedItem(name);
+ if (attrNode == null) return null;
+ return attrNode.getNodeValue();
+ }
+
+
+
+
+ private void dump(Node node, int indent) {
+ for (int i=0; i < indent; i++) System.out.print(" ");
+ System.out.println(node);
+ NodeList children = node.getChildNodes();
+ for (int i=0; i < children.getLength(); i++) {
+ dump(children.item(i), indent+1);
+ }
+ }
+
+
+}
diff --git a/testing/testsrc/org/aspectj/testing/harness/bridge/TestingBridgeTests.java b/testing/testsrc/org/aspectj/testing/harness/bridge/TestingBridgeTests.java
new file mode 100644
index 000000000..05d64b01d
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/harness/bridge/TestingBridgeTests.java
@@ -0,0 +1,32 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.testing.harness.bridge;
+
+import junit.framework.*;
+
+public class TestingBridgeTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(TestingBridgeTests.class.getName());
+ //$JUnit-BEGIN$
+ suite.addTestSuite(AjcSpecTest.class);
+ suite.addTestSuite(ParseTestCase.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+ public TestingBridgeTests(String name) { super(name); }
+
+}
diff --git a/testing/testsrc/org/aspectj/testing/util/BridgeUtilTest.java b/testing/testsrc/org/aspectj/testing/util/BridgeUtilTest.java
new file mode 100644
index 000000000..ae0a7cdac
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/util/BridgeUtilTest.java
@@ -0,0 +1,100 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+package org.aspectj.testing.util;
+
+import org.aspectj.bridge.MessageHandler;
+import org.aspectj.bridge.MessageUtil;
+import org.aspectj.testing.run.IRun;
+import org.aspectj.testing.run.IRunStatus;
+import org.aspectj.testing.run.RunStatus;
+import org.aspectj.testing.run.Runner;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class BridgeUtilTest extends TestCase {
+
+ public BridgeUtilTest(String name) {
+ super(name);
+ }
+
+ public void testChildString() {
+ String expect;
+ String id;
+ id = "run status identifier";
+ expect = "PASS " + id + " 0 tests";
+ checkChildString(id, 0, 0, 0, 0, expect);
+ expect = "PASS " + id + " 2 tests (2 skipped)";
+ checkChildString(id, 2, 0, 0, 0, expect);
+ expect = "PASS " + id + " 3 tests (1 skipped, 2 passed)";
+ checkChildString(id, 1, 0, 0, 2, expect);
+ expect = "FAIL " + id + " 3 tests (1 skipped, 2 failed)";
+ checkChildString(id, 1, 0, 2, 0, expect);
+ expect = "FAIL " + id + " 6 tests (1 skipped, 2 failed, 3 passed)";
+ checkChildString(id, 1, 0, 2, 3, expect);
+ expect = "FAIL " + id + " 1 tests (1 failed)";
+ checkChildString(id, 0, 0, 1, 0, expect);
+ expect = "FAIL " + id + " 4 tests (1 failed, 3 passed)";
+ checkChildString(id, 0, 0, 1, 3, expect);
+ expect = "PASS " + id + " 1 tests (1 passed)";
+ checkChildString(id, 0, 0, 0, 1, expect);
+
+ // "incomplete" variants
+ expect = "PASS " + id + " 5 tests (5 incomplete)";
+ checkChildString(id, 0, 5, 0, 0, expect);
+ expect = "PASS " + id + " 7 tests (2 skipped, 5 incomplete)";
+ checkChildString(id, 2, 5, 0, 0, expect);
+ expect = "PASS " + id + " 8 tests (1 skipped, 5 incomplete, 2 passed)";
+ checkChildString(id, 1, 5, 0, 2, expect);
+ expect = "FAIL " + id + " 8 tests (1 skipped, 5 incomplete, 2 failed)";
+ checkChildString(id, 1, 5, 2, 0, expect);
+ expect = "FAIL " + id + " 11 tests (1 skipped, 5 incomplete, 2 failed, 3 passed)";
+ checkChildString(id, 1, 5, 2, 3, expect);
+ expect = "FAIL " + id + " 6 tests (5 incomplete, 1 failed)";
+ checkChildString(id, 0, 5, 1, 0, expect);
+ expect = "FAIL " + id + " 9 tests (5 incomplete, 1 failed, 3 passed)";
+ checkChildString(id, 0, 5, 1, 3, expect);
+ expect = "PASS " + id + " 6 tests (5 incomplete, 1 passed)";
+ checkChildString(id, 0, 5, 0, 1, expect);
+ }
+
+ void checkChildString(String id, int numSkips, int numIncomplete, int numFails, int numPasses,
+ String expected) {
+ Runner runner = new Runner();
+ MessageHandler holder = new MessageHandler();
+ RunStatus status = new RunStatus(holder, runner);
+ status.setIdentifier(id);
+ status.start();
+
+ final IRun failer = new IRun() {
+ public boolean run(IRunStatus status) { return false; }
+ };
+ final IRun passer = new IRun() {
+ public boolean run(IRunStatus status) { return true; }
+ };
+ final Object result = (numFails > 0 ? IRunStatus.FAIL : IRunStatus.PASS);
+ while (numFails-- > 0) {
+ runner.runChild(failer,status, null, null);
+ }
+ while (numPasses-- > 0) {
+ runner.runChild(passer,status, null, null);
+ }
+ status.finish(result);
+ String actual = BridgeUtil.childString(status, numSkips, numIncomplete);
+ String label = " expected \"" + expected + "\" got \"" + actual + "\"";
+ assertTrue(label, expected.equals(actual));
+ }
+}
diff --git a/testing/testsrc/org/aspectj/testing/util/FileUtilTest.java b/testing/testsrc/org/aspectj/testing/util/FileUtilTest.java
new file mode 100644
index 000000000..1ff4d6cf6
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/util/FileUtilTest.java
@@ -0,0 +1,46 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+package org.aspectj.testing.util;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class FileUtilTest extends TestCase {
+
+ /**
+ * Constructor for FileUtilTest.
+ * @param arg0
+ */
+ public FileUtilTest(String arg0) {
+ super(arg0);
+ }
+
+ public void testFileEquals() {
+ // File.equals(..) is based on lexical compare of filenames
+// File rf = new File("testsrc/org/aspectj/testing/util/FileUtilTest.java");
+// File rb = new File("testsrc\\org\\aspectj\\testing\\util\\FileUtilTest.java");
+// String a = rf.getAbsolutePath().replace('\\', '/');
+// File af = new File(a);
+// File ab = new File(a.replace('/', '\\'));
+// list.add(af);
+// list.add(ab);
+// list.add(rb);
+// assertTrue(list.contains(duplicateTwo));
+// assertTrue(list.contains(anotherOne));
+ }
+}
diff --git a/testing/testsrc/org/aspectj/testing/util/IteratorWrapperTest.java b/testing/testsrc/org/aspectj/testing/util/IteratorWrapperTest.java
new file mode 100644
index 000000000..fdcd695ac
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/util/IteratorWrapperTest.java
@@ -0,0 +1,164 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+package org.aspectj.testing.util;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class IteratorWrapperTest extends TestCase {
+
+ /**
+ * Constructor for IteratorWrapperTest.
+ * @param name
+ */
+ public IteratorWrapperTest(String name) {
+ super(name);
+ }
+
+ public void testIteratorWrapper() {
+ Object[][] exp = new Object[][] {};
+ List[] in = new List[] {};
+ checkIteratorWrapper(in, exp);
+
+ in = new List[] {Collections.EMPTY_LIST};
+ checkIteratorWrapper(in, exp);
+
+ in = new List[] {Collections.EMPTY_LIST, Collections.EMPTY_LIST};
+ checkIteratorWrapper(in, exp);
+
+ Object[] ra1 = new Object[] { "1" };
+ List one = Collections.unmodifiableList(Arrays.asList(ra1));
+ in = new List[] {one};
+ exp = new Object[][] { ra1 };
+ checkIteratorWrapper(in, exp);
+
+ in = new List[] {one, one};
+ exp = new Object[][] { new Object[] { "1", "1"} };
+ checkIteratorWrapper(in, exp);
+
+ Object[] RA_ab = new String[] { "a", "b" };
+ List List_ab = Collections.unmodifiableList(Arrays.asList(RA_ab));
+ in = new List[] {List_ab};
+ exp = new Object[][] {
+ new Object[] { "a" },
+ new Object[] { "b" }
+ };
+ checkIteratorWrapper(in, exp);
+
+ in = new List[] {one, List_ab};
+ exp = new Object[][] {
+ new Object[] { "1", "a" },
+ new Object[] { "1", "b" },
+ };
+ checkIteratorWrapper(in, exp);
+
+ Object[] RA_cd = new String[] { "c", "d" };
+ List List_cd = Collections.unmodifiableList(Arrays.asList(RA_cd));
+
+ in = new List[] {List_ab, List_cd};
+ exp = new Object[][] {
+ new Object[] { "a", "c" },
+ new Object[] { "b", "c" },
+ new Object[] { "a", "d" },
+ new Object[] { "b", "d" }
+ };
+ checkIteratorWrapper(in, exp);
+
+ in = new List[] {one, one, one};
+ exp = new Object[][] {
+ new Object[] { "1", "1", "1" }
+ };
+ checkIteratorWrapper(in, exp);
+
+ in = new List[] {List_ab, List_ab, List_ab};
+ exp = new Object[][] {
+ new Object[] { "a", "a", "a" },
+ new Object[] { "b", "a", "a" },
+ new Object[] { "a", "b", "a" },
+ new Object[] { "b", "b", "a" },
+ new Object[] { "a", "a", "b" },
+ new Object[] { "b", "a", "b" },
+ new Object[] { "a", "b", "b" },
+ new Object[] { "b", "b", "b" }
+ };
+ checkIteratorWrapper(in, exp);
+
+ in = new List[] {one, List_ab, List_ab};
+ exp = new Object[][] {
+ new Object[] { "1", "a", "a" },
+ new Object[] { "1", "b", "a" },
+ new Object[] { "1", "a", "b" },
+ new Object[] { "1", "b", "b" },
+ };
+ checkIteratorWrapper(in, exp);
+
+ in = new List[] {one, List_ab, one};
+ exp = new Object[][] {
+ new Object[] { "1", "a", "1" },
+ new Object[] { "1", "b", "1" }
+ };
+ checkIteratorWrapper(in, exp);
+
+ in = new List[] {List_ab, one, List_ab};
+ exp = new Object[][] {
+ new Object[] { "a", "1", "a" },
+ new Object[] { "b", "1", "a" },
+ new Object[] { "a", "1", "b" },
+ new Object[] { "b", "1", "b" }
+ };
+ checkIteratorWrapper(in, exp);
+
+ in = new List[] {List_ab, one, List_ab, List_ab, Collections.EMPTY_LIST};
+ exp = new Object[][] {};
+ checkIteratorWrapper(in, exp);
+
+ }
+
+ void checkIteratorWrapper(List[] lists, Object[][] exp) {
+ IteratorWrapper it = new IteratorWrapper(lists);
+ for (int i = 0; i < exp.length; i++) {
+ Object[] e = exp[i];
+ if (!it.hasNext()) {
+ String s = "exp[" + i + "]: " + Arrays.asList(e) + " it=" + it;
+ assertTrue(s, false);
+ }
+ Object[] actual = (Object[]) it.next();
+ checkEquals(e, actual, i);
+ }
+ if (it.hasNext()) {
+ String s = "> " + exp.length + " it=" + it;
+ assertTrue(s, false);
+ }
+ }
+
+ void checkEquals(Object[] exp, Object[] actual, int index) {
+ if (null == exp) {
+ assertTrue(null == actual);
+ } else {
+ assertTrue(null != actual);
+ }
+ String s = "] exp=" + Arrays.asList(exp) + " act=" + Arrays.asList(actual);
+ assertTrue(s, exp.length == actual.length);
+ for (int i = 0; i < actual.length; i++) {
+ assertTrue(null != exp[i]);
+ assertTrue("[" + index + ", " + i + s, exp[i].equals(actual[i]));
+ }
+ }
+}
diff --git a/testing/testsrc/org/aspectj/testing/util/LangUtilTest.java b/testing/testsrc/org/aspectj/testing/util/LangUtilTest.java
new file mode 100644
index 000000000..ebdb21cc5
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/util/LangUtilTest.java
@@ -0,0 +1,342 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+package org.aspectj.testing.util;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+
+/**
+ *
+ * @author isberg
+ */
+public class LangUtilTest extends TestCase {
+
+ private static final String ME
+ = "org.aspectj.testing.util.LangUtilTest";
+
+ /** @param args ignored */
+ public static void main(String[] args) {
+ TestRunner.main(new String[] {ME});
+ }
+
+ /**
+ * Constructor for LangUtilTest.
+ * @param name
+ */
+ public LangUtilTest(String name) {
+ super(name);
+ }
+
+ void check(String l, StringTokenizer st, int max, String delim) {
+ for (int i = 0; i < max; i++) {
+ if ((i > 0) && (null != delim)) {
+ assertEquals(l, delim, st.nextToken());
+ }
+ assertEquals(l, ""+i, st.nextToken());
+ }
+ assertTrue(l, !st.hasMoreTokens());
+ }
+
+
+ void checkUnflatten(FTest test) {
+ String[] exp = test.unflattened;
+ ArrayList result = LangUtil.unflatten(test.toUnflatten, test.spec);
+ String label = test + " -> " + result;
+ assertNotNull(label, result);
+
+ assertEquals(label, exp.length, result.size());
+ for (int i = 0; i < exp.length; i++) {
+ assertEquals(label, exp[i], result.get(i));
+ }
+ }
+
+
+ public void skiptestUnflatten() {
+ LangUtil.FlattenSpec COMMA = LangUtil.FlattenSpec.COMMA;
+ LangUtil.FlattenSpec LIST = LangUtil.FlattenSpec.LIST;
+
+ FTest[] tests = new FTest[]
+ { new FTest("[]", new String[0], LIST)
+ , new FTest("[1]", new String[] {"1"}, LIST)
+ , new FTest("[1, 2]", new String[] {"1", "2"}, LIST)
+ , new FTest("[1,2]", new String[] {"1,2"}, LIST)
+ , new FTest("[1, 2, 3]", new String[] {"1","2","3"}, LIST)
+ };
+ for (int i = 0; i < tests.length; i++) {
+ checkUnflatten(tests[i]);
+ }
+ }
+
+
+ public void testArrayList() {
+ ArrayList l = new ArrayList();
+ l.add(null);
+ l.add(null);
+ assertTrue(null == l.get(0));
+ assertTrue(null == l.get(1));
+ assertTrue(2 == l.size());
+ assertEquals("[null, null]", "" + l);
+ }
+
+ public void testCombineStrings() {
+ String[] one = new String[]{};
+ String[] two = new String[]{};
+ String[] expect = new String[]{};
+ checkCombineStrings(one, two, expect);
+
+ one = new String[]{null};
+ two = new String[]{null};
+ expect = new String[]{};
+ checkCombineStrings(one, two, expect);
+
+ one = new String[]{"1"};
+ two = new String[]{null};
+ expect = new String[]{"1"};
+ checkCombineStrings(one, two, expect);
+
+ one = new String[]{null};
+ two = new String[]{"2"};
+ expect = new String[]{"2"};
+ checkCombineStrings(one, two, expect);
+
+ one = new String[]{"1"};
+ two = new String[]{"2"};
+ expect = new String[]{"1", "2"};
+ checkCombineStrings(one, two, expect);
+
+ one = new String[]{null, null, "1", null, null};
+ two = new String[]{null, "2", null};
+ expect = new String[]{"1", "2"};
+ checkCombineStrings(one, two, expect);
+
+ one = new String[]{"1", "2", "3", "4"};
+ two = new String[]{"5", null, "6"};
+ expect = new String[]{"1", "2", "3", "4", "5", "6"};
+ checkCombineStrings(one, two, expect);
+
+ }
+ void checkCombineStrings(String[] one, String[] two, String[] expected) {
+ String[] actual = LangUtil.combine(one, two);
+ String aString = LangUtil.arrayAsList(actual).toString();
+ String eString = LangUtil.arrayAsList(expected).toString();
+ String both = "actual=\"" + aString + "\" expected=\"" + eString + "\"";
+ assertTrue(both, aString.equals(eString));
+ }
+
+ final String[] sABCDE = new String[] {"A", "B", "C", "D", "E" };
+ final String[] sABC = new String[] {"A", "B", "C" };
+ final String[] sDE = new String[] {"D", "E" };
+ final String[] sabcde = new String[] {"a", "b", "c", "d", "e" };
+ final String[] sabc = new String[] {"a", "b", "c" };
+ final String[] sde = new String[] {"d", "e" };
+ final String[] s12345 = new String[] {"1", "2", "3", "4", "5" };
+ final String[] s13579 = new String[] {"1", "3", "5", "7", "9" };
+ final String[] s02468 = new String[] {"0", "2", "4", "6", "8" };
+ final String[] s135 = new String[] {"1", "3", "5" };
+ final String[] s79 = new String[] {"7", "9" };
+ final String[] s24 = new String[] {"2", "4" };
+ final String[] s0 = new String[] {"0"};
+ final String[] s068 = new String[] {"0", "6", "8" };
+ final boolean unmodifiable = true;
+ final boolean modifiable = false;
+ final List lABCDE = makeList(unmodifiable, sABCDE);
+ final List lABC = makeList(unmodifiable, sABC);
+ final List lDE = makeList(unmodifiable, sDE);
+ final List labcde = makeList(unmodifiable, sabcde);
+ final List labc = makeList(unmodifiable, sabc);
+ final List lde = makeList(unmodifiable, sde);
+ final List l12345 = makeList(unmodifiable, s12345);
+ final List l13579 = makeList(unmodifiable, s13579);
+ final List l02468 = makeList(unmodifiable, s02468);
+ final List l135 = makeList(unmodifiable, s135);
+ final List l79 = makeList(unmodifiable, s79);
+ final List l24 = makeList(unmodifiable, s24);
+ final List l0 = makeList(unmodifiable, s0);
+ final List l068 = makeList(unmodifiable, s068);
+ final List rlabcde = makeList(modifiable, sabcde);
+ final List rlabc = makeList(modifiable, sabc);
+ final List rlde = makeList(modifiable, sde);
+ final List rlABCDE = makeList(modifiable, sABCDE);
+ final List rlABC = makeList(modifiable, sABC);
+ final List rlDE = makeList(modifiable, sDE);
+ final List rl12345 = makeList(modifiable, s12345);
+ final List rl13579 = makeList(modifiable, s13579);
+ final List rl02468 = makeList(modifiable, s02468);
+ final List rl135 = makeList(modifiable, s135);
+ final List rl79 = makeList(modifiable, s79);
+ final List rl24 = makeList(modifiable, s24);
+ final List rl0 = makeList(modifiable, s0);
+ final List rl068 = makeList(modifiable, s068);
+ final List NONE = Collections.EMPTY_LIST;
+ {
+ Collections.shuffle(rlABCDE);
+ Collections.shuffle(rlABC);
+ Collections.shuffle(rlDE);
+ Collections.shuffle(rlabcde);
+ Collections.shuffle(rlabc);
+ Collections.shuffle(rlde);
+ Collections.shuffle(rl12345);
+ Collections.shuffle(rl13579);
+ Collections.shuffle(rl02468);
+ Collections.shuffle(rl135);
+ Collections.shuffle(rl79);
+ Collections.shuffle(rl24);
+ Collections.shuffle(rl0);
+ Collections.shuffle(rl068);
+ }
+
+
+ public void testDiffsEmptyIdentities() {
+ checkDiff(l02468, null, l02468, NONE);
+ checkDiff(null, l02468, NONE, l02468);
+ checkDiff(l0, null, l0, NONE);
+ checkDiff(null, l0, NONE, l0);
+ checkDiff(l0, rl0, NONE, NONE);
+ checkDiff(labc, rlabc, NONE, NONE);
+ }
+
+ public void testDiffsEmpties() {
+ checkDiff(NONE, NONE, NONE, NONE);
+ checkDiff(null, NONE, NONE, NONE);
+ checkDiff(NONE, null, NONE, NONE);
+ checkDiff(null, null, NONE, NONE);
+ checkDiff(null, null, NONE, NONE);
+ }
+
+ public void testDiffsIdentities() {
+ checkDiff(l02468, l02468, NONE, NONE);
+ checkDiff(rl02468, l02468, NONE, NONE);
+ checkDiff(l02468, rl02468, NONE, NONE);
+ checkDiff(l13579, l13579, NONE, NONE);
+ checkDiff(rl13579, l13579, NONE, NONE);
+ checkDiff(l13579, rl13579, NONE, NONE);
+ checkDiff(l13579, rl13579, NONE, NONE);
+ }
+ public void testDiffsEvens() {
+ checkDiff(l02468, l12345, l068, l135);
+ checkDiff(rl02468, rl12345, rl068, rl135);
+ }
+
+ public void testDiffsOdds() {
+ checkDiff(l13579, l12345, l79, l24);
+ checkDiff(rl13579, rl12345, rl79, rl24);
+ checkDiff(l13579, rl12345, l79, rl24);
+ checkDiff(rl13579, l12345, rl79, l24);
+ }
+
+ public void testSoftDiffs() {
+ checkDiffSoft(labcde, lABCDE, NONE, NONE);
+ checkDiffSoft(lABC, labc, NONE, NONE);
+ checkDiffSoft(lABCDE, lABC, lDE, NONE);
+ checkDiffSoft(lDE, lABCDE, NONE, lABC);
+ checkDiffSoft(rlABCDE, rlABC, rlDE, NONE);
+ checkDiffSoft(rlDE, rlABCDE, NONE, rlABC);
+ checkDiffSoft(labcde, lABC, lDE, NONE);
+ checkDiffSoft(lde, lABCDE, NONE, lABC);
+ checkDiffSoft(rlabcde, rlABC, rlDE, NONE);
+ checkDiffSoft(rlde, rlABCDE, NONE, rlABC);
+ }
+
+ // ---------------------- utilities
+ List makeList(boolean unmodifiable, String[] ra) {
+ if (unmodifiable) {
+ return Collections.unmodifiableList(Arrays.asList(ra));
+ } else {
+ ArrayList list = new ArrayList();
+ list.addAll(Arrays.asList(ra));
+ return list;
+ }
+ }
+
+ /** check both hard and soft - assuming list contain String */
+ void checkDiff(List expected, List actual, List missing, List extra) {
+ ArrayList extraOut = new ArrayList();
+ ArrayList missingOut = new ArrayList();
+ LangUtil.makeDiffs(expected, actual, missingOut, extraOut);
+ checkSame(missing, missingOut);
+ checkSame(extra, extraOut);
+ extraOut.clear();
+ missingOut.clear();
+
+ LangUtil.makeSoftDiffs(expected, actual, missingOut, extraOut,
+ String.CASE_INSENSITIVE_ORDER);
+ checkSame(missing, missingOut); // XXX does not detect bad order
+ checkSame(extra, extraOut);
+ }
+
+ void checkSame(Collection one, Collection two) { // just convert and string-compare?
+ String label = one + "?=" + two;
+ assertTrue(label, (null == one) == (null == two));
+ if (null != one) {
+ assertTrue(label, one.containsAll(two));
+ assertTrue(label, two.containsAll(one));
+ }
+ }
+
+ /** check only soft - assuming list contain String */
+ void checkDiffSoft(List expected, List actual, List missing, List extra) {
+ ArrayList extraOut = new ArrayList();
+ ArrayList missingOut = new ArrayList();
+ LangUtil.makeSoftDiffs(expected, actual, missingOut, extraOut,
+ String.CASE_INSENSITIVE_ORDER);
+ checkSameSoft(missing, missingOut);
+ checkSameSoft(extra, extraOut);
+ }
+
+ /** @param one modifiable List of String
+ * @param two modifiable List of String
+ */
+ void checkSameSoft(List one, List two) { // assume String
+ String label = one + "?=" + two;
+ assertTrue(label, (null == one) == (null == two));
+ if (null != one) {
+ ArrayList aone = new ArrayList();
+ aone.addAll(one);
+ ArrayList atwo = new ArrayList();
+ aone.addAll(two);
+ Collections.sort(aone);
+ Collections.sort(atwo);
+ String sone = (""+aone).toLowerCase();
+ String stwo = (""+aone).toLowerCase();
+ assertTrue(label, sone.equals(stwo));
+ }
+ }
+
+ static class FTest {
+ String toUnflatten;
+ String[] unflattened;
+ LangUtil.FlattenSpec spec;
+ FTest(String in, String[] out, LangUtil.FlattenSpec spec) {
+ toUnflatten = in;
+ unflattened = out;
+ this.spec = spec;
+ }
+ public String toString() {
+ return "FTest("
+ + "toUnflatten=" + toUnflatten
+ + ", unflattened=" + Arrays.asList(unflattened)
+ + ", spec=" + spec
+ + ")";
+ }
+ }
+
+
+}
diff --git a/testing/testsrc/org/aspectj/testing/util/MessageUtilTest.java b/testing/testsrc/org/aspectj/testing/util/MessageUtilTest.java
new file mode 100644
index 000000000..26d8523dd
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/util/MessageUtilTest.java
@@ -0,0 +1,130 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.testing.util;
+
+import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.bridge.Message;
+import org.aspectj.bridge.MessageHandler;
+import org.aspectj.bridge.MessageUtil;
+import org.aspectj.bridge.SourceLocation;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class MessageUtilTest extends TestCase {
+ public MessageUtilTest(String s) {
+ super(s);
+ }
+
+ MessageHandler samples;
+ List /* Exception */ exceptions;
+ List /*ISourceLocation*/ locations;
+ List /*String */ messageTexts;
+
+
+ public void testMessageRendering() {
+ MessageHandler messages = getSampleMessages();
+ System.out.println("testMessageRendering(): run manually evaluate by inspection");
+ PrintStream oldOut = System.out;
+ // comment to inspect manually
+ System.setOut(NullPrintStream.NULL_PrintStream);
+ try {
+ MessageUtil.print(System.out, messages, "all label -> ", MessageUtil.MESSAGE_LABEL, MessageUtil.PICK_ALL);
+ MessageUtil.print(System.out, messages, "info short -> ", MessageUtil.MESSAGE_SHORT, MessageUtil.PICK_INFO);
+ MessageUtil.print(System.out, messages, "fail line -> ", MessageUtil.MESSAGE_LINE, MessageUtil.PICK_FAIL);
+ MessageUtil.print(System.out, messages, "debug wide line -> ", MessageUtil.MESSAGE_WIDELINE, MessageUtil.PICK_DEBUG);
+ MessageUtil.print(System.out, messages, "warn no-loc label -> ", MessageUtil.MESSAGE_LABEL_NOLOC, MessageUtil.PICK_WARNING);
+ MessageUtil.print(System.out, messages, "abort force-loc line -> ", MessageUtil.MESSAGE_LINE_FORCE_LOC, MessageUtil.PICK_ABORT);
+ MessageUtil.print(System.out, messages, "info+ short -> ", MessageUtil.MESSAGE_SHORT, MessageUtil.PICK_INFO_PLUS);
+ MessageUtil.print(System.out, messages, "fail+ line -> ", MessageUtil.MESSAGE_LINE, MessageUtil.PICK_FAIL_PLUS);
+ MessageUtil.print(System.out, messages, "debug+ wide line -> ", MessageUtil.MESSAGE_WIDELINE, MessageUtil.PICK_DEBUG_PLUS);
+ MessageUtil.print(System.out, messages, "warn+ no-loc label -> ", MessageUtil.MESSAGE_LABEL_NOLOC, MessageUtil.PICK_WARNING_PLUS);
+ MessageUtil.print(System.out, messages, "abort+ force-loc line -> ", MessageUtil.MESSAGE_LINE_FORCE_LOC, MessageUtil.PICK_ABORT_PLUS);
+ } finally {
+ System.setOut(oldOut);
+ }
+ }
+
+
+ List getSampleMessageTexts() {
+ if (null == messageTexts) {
+ ArrayList result = new ArrayList();
+ result.addAll(Arrays.asList(new String[]
+ { "one", "two", "now is the time for all good men..." }));
+ messageTexts = result;
+ }
+ return messageTexts;
+ }
+
+ List getSampleExceptions() {
+ if (null == exceptions) {
+ ArrayList result = new ArrayList();
+ int i = 1;
+ result.add(new Error("Error " + i++));
+ result.add(new RuntimeException("RuntimeException " + i++));
+ result.add(new IOException("IOException " + i++));
+ exceptions = result;
+ }
+ return exceptions;
+ }
+
+ List getSampleLocations() {
+ if (null == locations) {
+ ArrayList result = new ArrayList();
+ File file = new File("testsrc/org/aspectj/testing/util/MessageUtilTest.java");
+ result.add(new SourceLocation(file, 1, 2, 1));
+ result.add(new SourceLocation(file, 100, 100, 0));
+ locations = result;
+ }
+ return locations;
+ }
+
+ MessageHandler getSampleMessages() {
+ MessageHandler result = new MessageHandler();
+ for (Iterator kinds = IMessage.KINDS.iterator(); kinds.hasNext();) {
+ IMessage.Kind kind = (IMessage.Kind) kinds.next();
+ for (Iterator locs = getSampleLocations().iterator(); locs.hasNext();) {
+ ISourceLocation sourceLoc = (ISourceLocation) locs.next();
+ for (Iterator texts = getSampleMessageTexts().iterator();
+ texts.hasNext();
+ ) {
+ String text = (String) texts.next();
+ for (Iterator exs = getSampleExceptions().iterator();
+ exs.hasNext();
+ ) {
+ Throwable thrown = (Throwable) exs.next();
+ result.handleMessage(new Message(text, kind, thrown, sourceLoc));
+ }
+ result.handleMessage(new Message(text, kind, null, sourceLoc));
+ }
+ result.handleMessage(new Message("", kind, null, sourceLoc));
+ }
+ result.handleMessage(new Message("", kind, null, null));
+ }
+ return result;
+ }
+
+}
diff --git a/testing/testsrc/org/aspectj/testing/util/StreamGrabberTest.java b/testing/testsrc/org/aspectj/testing/util/StreamGrabberTest.java
new file mode 100644
index 000000000..9cd882fa8
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/util/StreamGrabberTest.java
@@ -0,0 +1,112 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+/*
+ * StreamGrabberTest.java created on May 16, 2002
+ *
+ */
+package org.aspectj.testing.util;
+
+
+import java.io.PrintStream;
+
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+
+/**
+ *
+ * @author isberg
+ */
+public class StreamGrabberTest extends TestCase {
+
+
+ private static final String ME
+ = "org.aspectj.testing.util.StreamGrabberTest";
+
+ /** @param args ignored */
+ public static void main(String[] args) {
+ TestRunner.main(new String[] {ME});
+ }
+
+ public StreamGrabberTest(String s) { super(s); }
+
+ public void testHide() {
+ PrintStream restore = System.out;
+ System.setOut(new PrintStream(NullPrintStream.NULL_OutputStream));
+ System.out.println("OutputStream should not print!!!!!!!!!!!!!!!!!!!");
+ System.setOut(new PrintStream(NullPrintStream.NULL_PrintStream));
+ System.out.println("PrintStream should not print!!!!!!!!!!!!!!!!!!!");
+ System.setOut(restore);
+ }
+
+ /**
+ * Test StreamSniffer by setting up a delegate System.out
+ * and a normal System.out (delegating to System.out)
+ * and verifying that both get the same result.
+ */
+ public void testGrab() {
+ StringBuffer delegate = new StringBuffer();
+ StreamSniffer out = new StreamSniffer(System.out);
+ out.setBuffer(delegate);
+ System.setOut(new PrintStream(out));
+ StreamSniffer g = new StreamSniffer(System.out);
+ System.setOut(new PrintStream(g));
+ StringBuffer buf = new StringBuffer();
+ g.setBuffer(buf);
+
+ printLoop("f", buf, delegate);
+ printLoop("now is the time for all good men...", buf, delegate);
+ printlnLoop("f", buf, delegate);
+ printlnLoop("now is the time for all good men...", buf, delegate);
+ }
+
+ private void printLoop(String expect, StringBuffer buf, StringBuffer delegate) {
+ System.out.print(expect);
+ String actual = buf.toString();
+ String delegateActual = delegate.toString();
+ assertTrue(expect + "=" + actual, expect.equals(actual));
+ assertTrue(expect + "=" + delegateActual, expect.equals(delegateActual));
+ buf.setLength(0);
+ delegate.setLength(0);
+ System.out.print(expect);
+
+ actual = buf.toString();
+ delegateActual = delegate.toString();
+ assertTrue(expect + "=" + actual, expect.equals(actual));
+ assertTrue(expect + "=" + delegateActual, expect.equals(delegateActual));
+ buf.setLength(0);
+ delegate.setLength(0);
+ }
+
+ private void printlnLoop(String expect, StringBuffer buf, StringBuffer delegate) {
+ // copy/paste of printLoop, using println
+ expect = expect.trim();
+ System.out.println(expect);
+ String actual = buf.toString().trim();
+ String delegateActual = delegate.toString().trim();
+ assertTrue(expect + "=" + actual, expect.equals(actual));
+ assertTrue(expect + "=" + delegateActual, expect.equals(delegateActual));
+ buf.setLength(0);
+ delegate.setLength(0);
+
+ System.out.println(expect);
+ actual = buf.toString().trim();
+ delegateActual = delegate.toString().trim();
+ assertTrue(expect + "=" + actual, expect.equals(actual));
+ assertTrue(expect + "=" + delegateActual, expect.equals(delegateActual));
+ buf.setLength(0);
+ delegate.setLength(0);
+ }
+
+}
diff --git a/testing/testsrc/org/aspectj/testing/util/TestDiffsTest.java b/testing/testsrc/org/aspectj/testing/util/TestDiffsTest.java
new file mode 100644
index 000000000..4ce7792c6
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/util/TestDiffsTest.java
@@ -0,0 +1,114 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+package org.aspectj.testing.util;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.ListIterator;
+
+import junit.framework.TestCase;
+import org.aspectj.util.FileUtil;
+
+/**
+ *
+ */
+public class TestDiffsTest extends TestCase {
+
+ /**
+ * Expected results in test below.
+ */
+ private static void genTestInput(File expected, File actual) throws IOException {
+ FileWriter writer = null;
+ try {
+ writer = new FileWriter(expected);
+ PrintWriter pw = new PrintWriter(writer);
+ pw.println("PASS passed in both");
+ pw.println("## random text to ignore: " + System.currentTimeMillis());
+ pw.println("FAIL failed in both");
+ pw.println("PASS failed in actual (broken)");
+ pw.println("FAIL passed in actual (fixed)");
+ pw.println("PASS not in actual (missing-pass)");
+ pw.println("FAIL not in actual (missing-fail)");
+ pw.flush();
+ writer.close();
+
+ writer = new FileWriter(actual);
+ pw = new PrintWriter(writer);
+ pw.println("PASS passed in actual (fixed)");
+ pw.println("## random text to ignore: " + System.currentTimeMillis());
+ pw.println("PASS not in expected (added-pass)");
+ pw.println("FAIL failed in both");
+ pw.println("PASS passed in both");
+ pw.println("FAIL failed in actual (broken)");
+ pw.println("FAIL not in expected (added-fail)");
+ pw.flush();
+ writer.close();
+ writer = null;
+ } finally {
+ if (null != writer) {
+ try { writer.close(); }
+ catch (IOException e) { } // ignore
+ }
+ }
+ }
+
+ ArrayList tempFiles;
+ /**
+ * Constructor for FileUtilTest.
+ * @param arg0
+ */
+ public TestDiffsTest(String arg0) {
+ super(arg0);
+ tempFiles = new ArrayList();
+ }
+
+ public void tearDown() {
+ for (ListIterator iter = tempFiles.listIterator(); iter.hasNext();) {
+ File dir = (File) iter.next();
+ FileUtil.deleteContents(dir);
+ dir.delete();
+ iter.remove();
+ }
+ }
+
+
+ public void testCompareResults() {
+ File tempDir = org.aspectj.util.FileUtil.getTempDir("testCompareResults");
+ File expected = new File(tempDir, "expected.txt");
+ File actual = new File(tempDir, "actual.txt");
+ tempFiles.add(expected);
+ tempFiles.add(actual);
+ try {
+ genTestInput(expected, actual);
+ } catch (IOException e) {
+ assertTrue(e.getMessage(), false);
+ }
+ TestDiffs result = TestDiffs.compareResults(expected, actual);
+ assertEquals(2, result.missing.size());
+ assertEquals(2, result.added.size());
+ assertEquals(1, result.fixed.size());
+ assertEquals(1, result.broken.size());
+ assertEquals(3, result.actualFailed.size());
+ assertEquals(3, result.actualPassed.size());
+ assertEquals(6, result.actual.size());
+ assertEquals(3, result.expectedFailed.size());
+ assertEquals(3, result.expectedPassed.size());
+ assertEquals(6, result.expected.size());
+ assertEquals(1, result.stillFailing.size());
+ assertEquals(1, result.stillPassing.size());
+ }
+}
diff --git a/testing/testsrc/org/aspectj/testing/util/UtilTests.java b/testing/testsrc/org/aspectj/testing/util/UtilTests.java
new file mode 100644
index 000000000..3ec14d7df
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/util/UtilTests.java
@@ -0,0 +1,36 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.testing.util;
+
+import junit.framework.*;
+
+public class UtilTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(UtilTests.class.getName());
+ //$JUnit-BEGIN$
+ suite.addTestSuite(BridgeUtilTest.class);
+ suite.addTestSuite(FileUtilTest.class);
+ suite.addTestSuite(IteratorWrapperTest.class);
+ suite.addTestSuite(LangUtilTest.class);
+ suite.addTestSuite(MessageUtilTest.class);
+ suite.addTestSuite(StreamGrabberTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+ public UtilTests(String name) { super(name); }
+
+}
diff --git a/testing/testsrc/org/aspectj/testing/xml/AjcSpecXmlReaderTest.java b/testing/testsrc/org/aspectj/testing/xml/AjcSpecXmlReaderTest.java
new file mode 100644
index 000000000..157cf2dba
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/xml/AjcSpecXmlReaderTest.java
@@ -0,0 +1,236 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+package org.aspectj.testing.xml;
+
+import org.aspectj.bridge.MessageHandler;
+import org.aspectj.bridge.MessageUtil;
+import org.aspectj.testing.harness.bridge.AjcSpecTest;
+import org.aspectj.testing.harness.bridge.CompilerRun;
+import org.aspectj.testing.harness.bridge.FlatSuiteReader;
+import org.aspectj.testing.harness.bridge.AjcTest;
+import org.aspectj.testing.run.IRunStatus;
+import org.aspectj.testing.run.IRunValidator;
+import org.aspectj.testing.run.RunValidator;
+import org.aspectj.util.LangUtil;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class AjcSpecXmlReaderTest extends TestCase {
+
+ ArrayList tempFiles = new ArrayList();
+ /**
+ * Constructor for AjcSpecXmlReaderTest.
+ * @param name
+ */
+ public AjcSpecXmlReaderTest(String name) {
+ super(name);
+ }
+
+ public void setUp() {
+ tempFiles.clear();
+ //System.out.println("XXX test requires compiler and bridgeImpl projects on classpath");
+ }
+
+ public void tearDown() {
+ if (!LangUtil.isEmpty(tempFiles)) {
+ for (Iterator iter = tempFiles.iterator(); iter.hasNext();) {
+ File file = (File) iter.next();
+ if (file.canRead()) {
+ file.delete();
+ }
+ }
+ }
+ }
+
+ /** test that all AjcSpecXmlReader.me.expectedProperties() are bean-writable */
+ public void testBeanInfo() throws IntrospectionException {
+ AjcSpecXmlReader me = AjcSpecXmlReader.getReader();
+ AjcSpecXmlReader.BProps[] expected = me.expectedProperties();
+ PropertyDescriptor[] des;
+ for (int i = 0; i < expected.length; i++) {
+ Class clazz = expected[i].cl;
+ BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
+ assertTrue(null != beanInfo);
+ des = beanInfo.getPropertyDescriptors();
+ for (int j = 0; j < expected[i].props.length; j++) {
+ String name = expected[i].props[j];
+ String fqn = clazz.getName() + "." + name;
+ boolean gotIt = false;
+ for (int k = 0; k < des.length; k++) {
+ String desName = des[k].getName();
+ if (name.equals(desName)) {
+ assertTrue(fqn, null != des[k].getWriteMethod());
+ gotIt = true;
+ }
+ }
+ assertTrue("no such property: " + fqn, gotIt);
+ }
+ }
+
+ }
+ public void testAjcTests() throws IOException {
+ checkXmlRoundTrip("../tests/ajcTests");
+ }
+
+ public void testAjcTests10() throws IOException {
+ checkXmlRoundTrip("../tests/ajcTests10");
+ }
+
+ public void testAjcTestsBroken() throws IOException {
+ checkXmlRoundTrip("../tests/ajcTestsBroken");
+ }
+
+ public void testAjcTestsAttic() throws IOException {
+ checkXmlRoundTrip("../tests/ajcTestsAttic");
+ }
+
+ public void testAjcHarnessTests() throws IOException {
+ checkXmlRoundTrip("../tests/ajcHarnessTests");
+ }
+
+ void checkXmlRoundTrip(String path) throws IOException {
+ String xmlPath = path + ".xml";
+ String xml2Path = path + ".tmp.xml";
+
+ final File file1 = new File(xmlPath);
+ final ArrayList toDelete = new ArrayList();
+ final AjcSpecXmlReader writer = AjcSpecXmlReader.getReader();
+
+ assertTrue("" + file1, file1.canRead());
+ AjcTest.Suite.Spec suite1 = writer.readAjcSuite(file1);
+ assertNotNull(suite1);
+
+ File file2 = new File(xml2Path);
+ String warning = writer.writeSuiteToXmlFile(file2, suite1);
+ toDelete.add(file2);
+ assertTrue(warning, null == warning);
+
+ AjcTest.Suite.Spec suite2 = writer.readAjcSuite(file1);
+ assertNotNull(suite2);
+ AjcSpecTest.sameAjcSuiteSpec(suite1, suite2, this);
+
+ for (Iterator iter = toDelete.iterator(); iter.hasNext();) {
+ ((File) iter.next()).delete();
+ }
+ }
+
+ void checkRoundTrip(String path) throws IOException, Exception {
+ // XXX once .txt gone, add bugId and keywords to test
+ String txtPath = path + ".txt";
+ String xmlPath = path + ".tmp.xml";
+ String xml2Path = path + ".tmp2.xml";
+
+ // read flat, write the xml variant, read back, and compare
+ AjcSpecXmlReader writer = AjcSpecXmlReader.getReader();
+ File file0 = new File(txtPath);
+ File file1 = new File(xmlPath);
+ ArrayList toDelete = new ArrayList();
+ AjcTest.Suite.Spec suite0 = null;
+ if (file0.canRead()) {
+ System.out.println("reading " + file0);
+ suite0 = FlatSuiteReader.ME.readSuite(file0);
+ String warning = writer.writeSuiteToXmlFile(file1, suite0);
+ toDelete.add(file1);
+ assertTrue(warning, null == warning);
+ } else {
+ file1 = new File(path + ".xml");
+ if (file1.canRead()) {
+ System.out.println("reading " + file1);
+ suite0 = writer.readAjcSuite(file1);
+ } else {
+ System.err.println("Skipping as not in module: " + file0);
+ return;
+ }
+ }
+ assertNotNull(suite0);
+
+ //System.err.println("----------------------- suite0 " + txtPath);
+ //suite0.printAll(System.err, "");
+ assertTrue("" + file1, file1.canRead());
+ System.out.println("reading " + file1);
+ AjcTest.Suite.Spec suite1 = writer.readAjcSuite(file1);
+ assertNotNull(suite1);
+ //System.err.println("----------------------- suite1 " + xmlPath);
+ //suite0.printAll(System.err, "");
+ AjcSpecTest.sameAjcSuiteSpec(suite0, suite1, this);
+
+ // same for second-generation xml
+ file1 = new File(xml2Path);
+ String warning = writer.writeSuiteToXmlFile(file1, suite1);
+ toDelete.add(file1);
+ // XXX enable later assertTrue(warning, null == warning);
+ if (null != warning) {
+ System.out.println("warning " + file1 + ": " + warning);
+ }
+ System.out.println("reading " + file1);
+ AjcTest.Suite.Spec suite2 = writer.readAjcSuite(file1);
+ assertNotNull(suite2);
+ //System.err.println("----------------------- suite2 " + xml2Path);
+ AjcSpecTest.sameAjcSuiteSpec(suite1, suite2, this);
+ AjcSpecTest.sameAjcSuiteSpec(suite0, suite2, this);
+
+ for (Iterator iter = toDelete.iterator(); iter.hasNext();) {
+ ((File) iter.next()).delete();
+ }
+ }
+}
+
+ // ------------------- XXX retry execution round-trips when eclipse working
+ //AjcSpecTest.sameAjcTestSpec(txtList, xmlSpec, this);
+
+// List xmlList = writer.readAjcTests(xmlFile);
+// AjcSpecTest.sameAjcTestLists(txtList, xmlList, this);
+// List xml2List = writer.readAjcTests(xmlFile);
+// AjcSpecTest.sameAjcTestLists(xmlList, xml2List, this);
+
+
+ // ------------------ now run them both and compare results
+// // run the flat and xml variants, then compare
+// MessageHandler xmlHandler = new MessageHandler();
+// IRunStatus xmlStatus = runFile(xmlPath, xmlHandler);
+// MessageHandler txtHandler = new MessageHandler();
+// IRunStatus txtStatus = runFile(txtPath, txtHandler);
+//
+//
+// // both should pass or fail..
+// IRunValidator v = RunValidator.NORMAL;
+// boolean xmlPassed = v.runPassed(xmlStatus);
+// boolean txtPassed = v.runPassed(txtStatus);
+// boolean passed = (xmlPassed == txtPassed);
+// if (!xmlPassed) {
+// MessageUtil.print(System.err, xmlStatus);
+// }
+// if (!txtPassed) {
+// MessageUtil.print(System.err, txtStatus);
+// }
+// if (!passed) { // calculate diffs
+// }
+// IRunStatus runFile(String path, MessageHandler handler) throws IOException {
+// Main runner = new Main(new String[] {path}, handler);
+// String id = "AjcSpecXmlReaderTest.runFile(" + path + ")";
+// return runner.runMain(id, handler, System.err);
+// }
diff --git a/testing/testsrc/org/aspectj/testing/xml/TestingXmlTests.java b/testing/testsrc/org/aspectj/testing/xml/TestingXmlTests.java
new file mode 100644
index 000000000..fbefdba5d
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/xml/TestingXmlTests.java
@@ -0,0 +1,31 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.testing.xml;
+
+import junit.framework.*;
+
+public class TestingXmlTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(TestingXmlTests.class.getName());
+ //$JUnit-BEGIN$
+ suite.addTestSuite(AjcSpecXmlReaderTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+ public TestingXmlTests(String name) { super(name); }
+
+}
diff --git a/testing/testsrc/org/aspectj/testing/xml/XMLWriterTest.java b/testing/testsrc/org/aspectj/testing/xml/XMLWriterTest.java
new file mode 100644
index 000000000..80790773e
--- /dev/null
+++ b/testing/testsrc/org/aspectj/testing/xml/XMLWriterTest.java
@@ -0,0 +1,44 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+package org.aspectj.testing.xml;
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class XMLWriterTest extends TestCase {
+
+ public XMLWriterTest(String name) {
+ super(name);
+ }
+
+ /** @see LangUtilTest#testCommaSplit() */
+ public void testUnflattenList() {
+ checkUnflattenList("", new String[] {""});
+ checkUnflattenList("1", new String[] {"1"});
+ checkUnflattenList(" 1 2 ", new String[] {"1 2"});
+ checkUnflattenList(" 1 , 2 ", new String[] {"1", "2"});
+ checkUnflattenList("1,2,3,4", new String[] {"1", "2", "3", "4"});
+ }
+
+ void checkUnflattenList(String input, String[] expected) {
+ String[] actual = XMLWriter.unflattenList(input);
+ String a = "" + Arrays.asList(actual);
+ String e = "" + Arrays.asList(expected);
+ assertTrue(e + "==" + a, e.equals(a));
+ }
+}