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.AbsentInformationException;
017: import com.sun.jdi.Locatable;
018: import com.sun.jdi.Location;
019: import com.sun.jdi.request.AccessWatchpointRequest;
020: import com.sun.jdi.request.BreakpointRequest;
021: import com.sun.jdi.request.ModificationWatchpointRequest;
022:
023: /**
024: * Tests for JDI com.sun.jdi.Locatable.
025: */
026: public class LocatableTest extends AbstractJDITest {
027:
028: private List fLocatables = new LinkedList();
029: private List fRequests = new LinkedList();
030:
031: /**
032: * Creates a new test.
033: */
034: public LocatableTest() {
035: super ();
036: }
037:
038: /**
039: * Init the fields that are used by this test only.
040: */
041: public void localSetUp() {
042: // Get all kinds of locatable
043:
044: BreakpointRequest bp = getBreakpointRequest();
045: fLocatables.add(bp); // BreakpointRequest
046:
047: //ExceptionRequest er = getExceptionRequest();
048: //fLocatables.add(triggerAndWait(er, 'e')); // ExceptionEvent
049:
050: fLocatables.add(getMethod()); // Method
051:
052: fLocatables.add(triggerStepAndWait()); // StepEvent
053:
054: fRequests.add(bp);
055: fLocatables.add(triggerAndWait(bp, "BreakpointEvent", true));
056: // BreakpointEvent
057:
058: if (fVM.canWatchFieldAccess()) {
059: AccessWatchpointRequest ap = getAccessWatchpointRequest();
060: fRequests.add(ap);
061: fLocatables.add(triggerAndWait(ap, "AccessWatchpointEvent",
062: true));
063: // AccessWatchpointEvent
064: }
065:
066: if (fVM.canWatchFieldModification()) {
067: ModificationWatchpointRequest mp = getModificationWatchpointRequest();
068: fRequests.add(mp);
069: fLocatables.add(triggerAndWait(mp,
070: "ModificationWatchpointEvent", false));
071: // ModificationWatchpointEvent
072: }
073:
074: // Note we can use the stack frame only if the thread is suspended,
075: // that's why the previoue triggerAndWait doesn't resume the thread
076: // and this Locatable is added last in the list
077: fLocatables.add(getFrame(RUN_FRAME_OFFSET)); // StackFrame
078:
079: }
080:
081: /**
082: * Make sure the test leaves the VM in the same state it found it.
083: */
084: public void localTearDown() {
085: // Ensure that the modification of the "fBool" field has completed
086: fVM.resume();
087: waitUntilReady();
088:
089: // Delete the event requests we created in this test
090: fVM.eventRequestManager().deleteEventRequests(fRequests);
091:
092: // Set the value of the "fBool" field back to its original value
093: resetField();
094: }
095:
096: /**
097: * Run all tests and output to standard output.
098: * @param args
099: */
100: public static void main(java.lang.String[] args) {
101: new LocatableTest().runSuite(args);
102: }
103:
104: /**
105: * Gets the name of the test case.
106: * @see junit.framework.TestCase#getName()
107: */
108: public String getName() {
109: return "com.sun.jdi.Locatable";
110: }
111:
112: /**
113: * Test JDI location()
114: */
115: public void testJDILocation() {
116: ListIterator iterator = fLocatables.listIterator();
117: while (iterator.hasNext()) {
118: Locatable locatable = (Locatable) iterator.next();
119: Location location = locatable.location();
120: assertTrue("1." + locatable, location != null);
121: assertTrue("2." + locatable, (location.codeIndex()) >= 0
122: || (location.codeIndex() == -1));
123: assertTrue("3." + locatable,
124: location.declaringType() != null);
125: assertTrue("4." + locatable, (location.lineNumber() > 0)
126: || (location.lineNumber() == -1));
127: assertNotNull("5", location.method());
128: try {
129: location.sourceName();
130: } catch (AbsentInformationException e) {
131: assertTrue("7", false);
132: }
133: }
134: }
135: }
|