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.util.LinkedList;
013: import java.util.List;
014: import java.util.ListIterator;
015:
016: import com.sun.jdi.Mirror;
017: import com.sun.jdi.request.AccessWatchpointRequest;
018: import com.sun.jdi.request.BreakpointRequest;
019: import com.sun.jdi.request.ModificationWatchpointRequest;
020:
021: /**
022: * Tests for JDI com.sun.jdi.Mirror.
023: */
024: public class MirrorTest extends AbstractJDITest {
025: List fMirrors = new LinkedList();
026:
027: /**
028: * Creates a new test.
029: */
030: public MirrorTest() {
031: super ();
032: }
033:
034: /**
035: * Init the fields that are used by this test only.
036: */
037: public void localSetUp() {
038: // Get all kinds of concrete mirror that can be found in the VM
039: // in alphabetical order.
040:
041: //TO DO: Add events too
042:
043: fMirrors = new LinkedList();
044:
045: if (fVM.canWatchFieldAccess())
046: fMirrors.add(getAccessWatchpointRequest());
047: // AccessWatchpointRequest
048:
049: fMirrors.add(getObjectArrayReference()); // ArrayReference
050: fMirrors.add(getArrayType()); // ArrayType
051: fMirrors.add(fVM.mirrorOf(true)); // BooleanValue
052: fMirrors.add(getBreakpointRequest()); // BreakpointRequest
053: fMirrors.add(fVM.mirrorOf((byte) 1)); // ByteValue
054: fMirrors.add(fVM.mirrorOf('1')); // CharValue
055: fMirrors.add(getClassLoaderReference()); // ClassLoaderReference
056: fMirrors.add(getMainClass()); // ClassType
057: fMirrors.add(fVM.mirrorOf(12345.6789)); // DoubleValue
058: fMirrors.add(fVM.eventRequestManager()); // EventRequestManager
059: fMirrors.add(fVM.eventQueue()); // EventQueue
060: fMirrors.add(getField()); // Field
061: fMirrors.add(fVM.mirrorOf(123.45f)); // FieldValue
062: fMirrors.add(fVM.mirrorOf(12345)); // IntegerValue
063: fMirrors.add(getInterfaceType()); // InterfaceType
064: fMirrors.add(getLocalVariable()); // LocalVariable
065: fMirrors.add(getLocation()); // Location
066: fMirrors.add(fVM.mirrorOf(123456789l)); // LongValue
067: fMirrors.add(getMethod()); // Method
068:
069: if (fVM.canWatchFieldModification())
070: fMirrors.add(getModificationWatchpointRequest());
071: // ModificationWatchpointRequest
072:
073: fMirrors.add(getObjectReference()); // ObjectReference
074: fMirrors.add(fVM.mirrorOf((short) 12345)); // ShortValue
075: fMirrors.add(getFrame(RUN_FRAME_OFFSET)); // StackFrame
076: fMirrors.add(getStringReference()); // StringReference
077: fMirrors.add(getThread().threadGroup()); // ThreadGroupReference
078: fMirrors.add(getThread()); // ThreadReference
079: fMirrors.add(fVM); // VirtualMachine
080: }
081:
082: /**
083: * Make sure the test leaves the VM in the same state it found it.
084: */
085: public void localTearDown() {
086: ListIterator iterator = fMirrors.listIterator();
087: while (iterator.hasNext()) {
088: Object mirror = iterator.next();
089:
090: // Delete the access watchpoint request we created in this test
091: if (mirror instanceof AccessWatchpointRequest)
092: fVM.eventRequestManager().deleteEventRequest(
093: (AccessWatchpointRequest) mirror);
094:
095: // Delete the breakpoint request we created in this test
096: if (mirror instanceof BreakpointRequest)
097: fVM.eventRequestManager().deleteEventRequest(
098: (BreakpointRequest) mirror);
099:
100: // Delete the modification watchpoint request we created in this test
101: if (mirror instanceof ModificationWatchpointRequest)
102: fVM.eventRequestManager().deleteEventRequest(
103: (ModificationWatchpointRequest) mirror);
104: }
105: }
106:
107: /**
108: * Run all tests and output to standard output.
109: * @param args
110: */
111: public static void main(java.lang.String[] args) {
112: new MirrorTest().runSuite(args);
113: }
114:
115: /**
116: * Gets the name of the test case.
117: * @see junit.framework.TestCase#getName()
118: */
119: public String getName() {
120: return "com.sun.jdi.Mirror";
121: }
122:
123: /**
124: * Test JDI toString().
125: */
126: public void testJDIToString() {
127: for (int i = 0; i < fMirrors.size(); i++) {
128: Mirror mirror = (Mirror) fMirrors.get(i);
129: assertNotNull(Integer.toString(i), mirror.toString());
130: }
131: }
132:
133: /**
134: * Test JDI virtualMachine().
135: */
136: public void testJDIVirtualMachine() {
137: for (int i = 0; i < fMirrors.size(); i++) {
138: Mirror mirror = (Mirror) fMirrors.get(i);
139: assertEquals(Integer.toString(i), fVM, mirror
140: .virtualMachine());
141: }
142: }
143: }
|