001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.debug.jdi.tests;
011:
012: import java.lang.reflect.Constructor;
013: import java.lang.reflect.InvocationTargetException;
014: import java.util.Enumeration;
015: import java.util.Vector;
016:
017: /**
018: * Run all tests
019: */
020: public class TestAll {
021: /**
022: * Returns all the test case classes (a Vector of Class) that are
023: * relevant for the given VM information.
024: * NB1: This doesn't include the VirtualMachineTest class.
025: * NB2: The last element must be the VMDeathEventTest class since
026: * it shuts the VM down.
027: */
028: protected static Vector getAllTestCases(VMInformation info) {
029: Vector classes = new Vector();
030: classes.addElement(AccessibleTest.class);
031: classes.addElement(ArrayReferenceTest.class);
032: classes.addElement(ArrayTypeTest.class);
033: classes.addElement(BooleanValueTest.class);
034: classes.addElement(BreakpointRequestTest.class);
035: classes.addElement(ByteValueTest.class);
036: classes.addElement(CharValueTest.class);
037: classes.addElement(ClassLoaderReferenceTest.class);
038: classes.addElement(ClassPrepareEventTest.class);
039: classes.addElement(ClassPrepareRequestTest.class);
040: classes.addElement(ClassTypeTest.class);
041: classes.addElement(DoubleValueTest.class);
042: classes.addElement(EventRequestManagerTest.class);
043: classes.addElement(EventRequestTest.class);
044: classes.addElement(EventTest.class);
045: classes.addElement(ExceptionEventTest.class);
046: classes.addElement(ExceptionRequestTest.class);
047: classes.addElement(FieldTest.class);
048: classes.addElement(FloatValueTest.class);
049: classes.addElement(HotCodeReplacementTest.class);
050: classes.addElement(IntegerValueTest.class);
051: classes.addElement(InterfaceTypeTest.class);
052: classes.addElement(LocalVariableTest.class);
053: classes.addElement(LocatableTest.class);
054: classes.addElement(LocationTest.class);
055: classes.addElement(LongValueTest.class);
056: classes.addElement(MethodTest.class);
057: classes.addElement(MethodEntryRequestTest.class);
058: classes.addElement(MethodExitRequestTest.class);
059: classes.addElement(MirrorTest.class);
060:
061: if (info.fVM.canWatchFieldModification())
062: classes.addElement(ModificationWatchpointEventTest.class);
063:
064: classes.addElement(ObjectReferenceTest.class);
065: classes.addElement(PrimitiveValueTest.class);
066: classes.addElement(ReferenceTypeTest.class);
067: classes.addElement(ShortValueTest.class);
068: classes.addElement(StackFrameTest.class);
069: classes.addElement(StepEventTest.class);
070: classes.addElement(StringReferenceTest.class);
071: classes.addElement(ThreadDeathEventTest.class);
072: classes.addElement(ThreadGroupReferenceTest.class);
073: classes.addElement(ThreadReferenceTest.class);
074: classes.addElement(ThreadStartEventTest.class);
075: classes.addElement(TypeComponentTest.class);
076: classes.addElement(TypeTest.class);
077: classes.addElement(ValueTest.class);
078:
079: if (info.fVM.canWatchFieldAccess()
080: && info.fVM.canWatchFieldModification()) {
081: classes.addElement(WatchpointEventTest.class);
082: classes.addElement(WatchpointRequestTest.class);
083: }
084:
085: classes.addElement(VirtualMachineExitTest.class);
086: classes.addElement(VMDisconnectEventTest.class);
087: classes.addElement(VMDisposeTest.class); // note that this test does not restore the state properly.
088: return classes;
089: }
090:
091: /**
092: * Run all tests with the given arguments.
093: * @see AbstractJDITest for details on the arguments.
094: * @param arguments
095: * @throws Throwable
096: */
097: public static void main(String[] arguments) throws Throwable {
098: // Create test result
099: TextTestResult result = new TextTestResult();
100:
101: // Run the VirtualMachineTest
102: AbstractJDITest test = run(result, VirtualMachineTest.class,
103: arguments, null);
104:
105: // Was it possible to run the first test?
106: if (test == null)
107: return;
108:
109: // Get the VM info
110: VMInformation info = test.getVMInfo();
111:
112: // Get all test cases
113: Vector classes = getAllTestCases(info);
114:
115: // Run the other tests
116: Enumeration enumeration = classes.elements();
117: while (enumeration.hasMoreElements()) {
118: Class testClass = (Class) enumeration.nextElement();
119: test = run(result, testClass, arguments, info);
120: info = test.getVMInfo(); // In case the test has changed this info
121: }
122:
123: // Shut down the VM
124: test.shutDownTarget();
125:
126: // Show the result
127: result.print();
128: }
129:
130: /**
131: * Runs the given test with the given arguments.
132: * Returns the instance that was created.
133: * Returns null if there was a problem with the arguments.
134: * @see AbstractJDITest for details on the arguments.
135: */
136: private static AbstractJDITest run(
137: junit.framework.TestResult result, Class testClass,
138: String[] arguments, VMInformation info) throws Throwable {
139: // Create test
140: Class[] argTypes = {};
141: Constructor construct = null;
142: try {
143: construct = testClass.getConstructor(argTypes);
144: } catch (NoSuchMethodException e) {
145: }
146: AbstractJDITest test = null;
147: try {
148: test = (AbstractJDITest) construct
149: .newInstance(new Object[] {});
150: } catch (InstantiationException e) {
151: } catch (IllegalAccessException e) {
152: } catch (InvocationTargetException e) {
153: throw e.getTargetException();
154: }
155: if (!AbstractJDITest.parseArgs(arguments))
156: return null;
157: test.setVMInfo(info);
158: test.setInControl(false);
159:
160: // Run test
161: System.out.println("\n" + new java.util.Date());
162: System.out.println("Begin testing " + test.getName() + "...");
163: long startTime = System.currentTimeMillis();
164: test.suite().run(result);
165: long endTime = System.currentTimeMillis();
166: long runTime = endTime - startTime;
167: System.out.println("\nTime: " + runTime / 1000 + "." + runTime
168: % 1000);
169: System.out.println("Done testing " + test.getName() + ".");
170:
171: return test;
172: }
173: }
|