aboutsummaryrefslogtreecommitdiffstats
path: root/testing-client/testsrc
diff options
context:
space:
mode:
authorwisberg <wisberg>2002-12-30 15:35:02 +0000
committerwisberg <wisberg>2002-12-30 15:35:02 +0000
commit0b35a034d72342ae120859a130ed245dfd63048e (patch)
treefbb46fe94c2b336d168af73c3f185bb6527fefbf /testing-client/testsrc
parente77b357e1194eabff59ef7f4bb862edfbec00c76 (diff)
downloadaspectj-0b35a034d72342ae120859a130ed245dfd63048e.tar.gz
aspectj-0b35a034d72342ae120859a130ed245dfd63048e.zip
minor Tester API tests brought down from attic
Diffstat (limited to 'testing-client/testsrc')
-rw-r--r--testing-client/testsrc/TestingClientModuleTests.java4
-rw-r--r--testing-client/testsrc/org/aspectj/testing/TesterTest.java234
-rw-r--r--testing-client/testsrc/org/aspectj/testing/TestingTests.java32
3 files changed, 268 insertions, 2 deletions
diff --git a/testing-client/testsrc/TestingClientModuleTests.java b/testing-client/testsrc/TestingClientModuleTests.java
index 7148e03e5..2abb09fe4 100644
--- a/testing-client/testsrc/TestingClientModuleTests.java
+++ b/testing-client/testsrc/TestingClientModuleTests.java
@@ -16,16 +16,16 @@
import junit.framework.*;
import junit.framework.Test;
+import org.aspectj.testing.TestingTests;
public class TestingClientModuleTests extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite(TestingClientModuleTests.class.getName());
- suite.addTestSuite(TestingClientModuleTests.class); // minimum 1 test (testNothing)
+ suite.addTest(TestingTests.suite());
return suite;
}
public TestingClientModuleTests(String name) { super(name); }
- public void testNothing() {}
}
diff --git a/testing-client/testsrc/org/aspectj/testing/TesterTest.java b/testing-client/testsrc/org/aspectj/testing/TesterTest.java
new file mode 100644
index 000000000..5acce235d
--- /dev/null
+++ b/testing-client/testsrc/org/aspectj/testing/TesterTest.java
@@ -0,0 +1,234 @@
+/* *******************************************************************
+ * 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;
+
+import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.IMessageHandler;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+
+/**
+ * Test the Tester client API's.
+ * See also tests/harness/*.java and tests/ajcHarnessTests.xml for harness-
+ * driven Tester tests.
+ * @author isberg
+ */
+public class TesterTest extends TestCase {
+
+
+ private static final String ME
+ = "org.aspectj.testing.TesterTest";
+
+ /** @param args ignored */
+ public static void main(String[] args) {
+ TestRunner.main(new String[] {ME});
+ }
+
+ /**
+ * Constructor for TesterTest.
+ * @param arg0
+ */
+ public TesterTest(String arg0) {
+ super(arg0);
+ }
+
+ /**
+ * Test the usage pattern
+ * <pre>Tester.event("foo");
+ * Tester.checkEvents(new String[] { "foo" }); </pre>
+ */
+ public void testEventArrayPattern() {
+ MyTestReporter reporter = new MyTestReporter();
+ Tester.setMessageHandler(reporter);
+
+ //--------- positive test - got expected events
+ reporter.clear();
+ Tester.clear();
+ Tester.event("one");
+ Tester.event("two");
+ Tester.checkEvents(new String[] { "one", "two"});
+ reporter.assertSize(0);
+
+ //--------- failed to get expected events
+ reporter.clear();
+ Tester.clear();
+ Tester.checkEvents(new String[] { "one"});
+ assertTrue(reporter.gotFail("one"));
+ reporter.assertSize(1);
+
+ //--------- got and didn't get expected events
+ reporter.clear();
+ Tester.clear();
+ Tester.event("one");
+ Tester.event("two");
+ Tester.checkEvents(new String[] { "one", "two", "three"});
+ reporter.assertSize(1);
+ assertTrue(reporter.gotFail("three"));
+ }
+
+ /**
+ * Test the usage pattern
+ * <pre>Tester.event("foo");
+ * Tester.expectEvent("foo");
+ * Tester.checkAllEvents();</pre>
+ */
+ public void testEventStringPattern() {
+ MyTestReporter reporter = new MyTestReporter();
+ Tester.setMessageHandler(reporter);
+
+ //--------- positive test - got expected events
+ reporter.clear();
+ Tester.clear();
+ Tester.event("one");
+ Tester.event("two");
+ Tester.expectEvent("one");
+ Tester.expectEvent("two");
+ Tester.checkAllEvents();
+ reporter.assertSize(0);
+
+ //--------- failed to get expected events
+ reporter.clear();
+ Tester.clear();
+ Tester.expectEvent("one");
+ Tester.checkAllEvents();
+ assertTrue(reporter.gotFail("one"));
+ reporter.assertSize(1);
+
+ //--------- got and didn't get expected events
+ reporter.clear();
+ Tester.clear();
+ Tester.expectEvent("one");
+ Tester.expectEvent("two");
+ Tester.expectEvent("three");
+ Tester.event("one");
+ Tester.event("two");
+ Tester.checkAllEvents();
+ assertTrue(reporter.gotFail("three"));
+ reporter.assertSize(1);
+ }
+
+ /**
+ * Test the usage pattern
+ * <pre>Tester.note("foo");
+ * Tester.check("foo");</pre>
+ */
+ public void testNotePattern() {
+ MyTestReporter reporter = new MyTestReporter();
+ Tester.setMessageHandler(reporter);
+
+ //--------- positive test - got expected events
+ reporter.clear();
+ Tester.clear();
+ Tester.note("one");
+ Tester.note("two");
+ Tester.check("one");
+ Tester.check("two");
+ reporter.assertSize(0);
+
+ //--------- failed to get expected events
+ reporter.clear();
+ Tester.clear();
+ Tester.check("one");
+ Tester.checkAllEvents();
+ assertTrue(reporter.gotFail("one"));
+ reporter.assertSize(1);
+
+ //--------- got and didn't get expected events
+ reporter.clear();
+ Tester.clear();
+ Tester.note("one");
+ Tester.check("one");
+ Tester.note("two");
+ Tester.check("two");
+ Tester.check("three");
+ assertTrue(reporter.gotFail("three"));
+ reporter.assertSize(1);
+ }
+
+ /**
+ * Stub to record failures emitted by Tester.
+ * @author isberg
+ */
+ public static class MyTestReporter implements IMessageHandler {
+ public ArrayList failures = new ArrayList();
+ public ArrayList passes = new ArrayList();
+
+ public void clear() {
+ failures.clear();
+ passes.clear();
+ }
+
+ void assertSize(int size) {
+ assertTrue(-1 < size);
+ assertTrue("failures: " + failures, size == failures.size());
+ }
+
+ boolean gotPass(String substring) {
+ return gotItem(passes, substring);
+ }
+
+ boolean gotFail(String substring) {
+ return gotItem(failures, substring);
+ }
+
+ boolean gotItem(List list, String substring) {
+ for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {
+ IMessage element = (IMessage) iterator.next();
+ String s = element.getMessage();
+ if ((null != s) && (-1 != s.indexOf(substring))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean isIgnoring(IMessage.Kind kind) {
+ return false;
+ }
+
+ public boolean handleMessage(IMessage message) {
+ (message.isFailed() ? failures : passes).add(message);
+ return true;
+ }
+
+ }
+}
+// /**
+// * @see ReporterI#abortWithFailure(String, Throwable)
+// */
+// public void abortWithFailure(String message, Throwable exception) {
+// if (null == exception) {
+// check(message, true);
+// } else {
+// String s = message + Util.unqualifiedClassName(exception)
+// + ": " + exception.getMessage();
+// check(s, false);
+// }
+// }
+//
+// /**
+// * @see ReporterI#check(String, boolean)
+// */
+// public boolean check(String message, boolean passed) {
+// (!passed ? failures : passes).add(message);
+// return passed;
+// }
+//
+
diff --git a/testing-client/testsrc/org/aspectj/testing/TestingTests.java b/testing-client/testsrc/org/aspectj/testing/TestingTests.java
new file mode 100644
index 000000000..99ac8678c
--- /dev/null
+++ b/testing-client/testsrc/org/aspectj/testing/TestingTests.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;
+
+import junit.framework.*;
+
+public class TestingTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(TestingTests.class.getName());
+ // for now, do not include SuiteTest because it would take 15 minutes
+ //$JUnit-BEGIN$
+ suite.addTestSuite(TesterTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+ public TestingTests(String name) { super(name); }
+
+}