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.HashMap;
013: import java.util.Iterator;
014: import java.util.LinkedList;
015:
016: import com.sun.jdi.event.Event;
017: import com.sun.jdi.request.EventRequest;
018:
019: /**
020: * Tests for JDI com.sun.jdi.event.Event.
021: */
022: public class EventTest extends AbstractJDITest {
023: private HashMap fAllEvents = new HashMap();
024:
025: /**
026: * Creates a new test.
027: */
028: public EventTest() {
029: super ();
030: }
031:
032: /**
033: * Init the fields that are used by this test only.
034: */
035: public void localSetUp() {
036: // All events...
037:
038: EventRequest request;
039:
040: // AccessWatchpointEvent
041: if (fVM.canWatchFieldAccess()) {
042: request = getAccessWatchpointRequest();
043: fAllEvents.put(request, triggerAndWait(request,
044: "AccessWatchpointEvent", true));
045: }
046:
047: // BreakpointEvent
048: request = getBreakpointRequest();
049: fAllEvents.put(request, triggerAndWait(request,
050: "BreakpointEvent", true));
051:
052: // TODO ClassPrepareEvent
053: // TODO ClassUnloadEvent
054: // TODO ExceptionEvent
055:
056: // ModificationWatchpointEvent
057: if (fVM.canWatchFieldModification()) {
058: request = getModificationWatchpointRequest();
059: fAllEvents.put(request, triggerAndWait(request,
060: "ModificationWatchpointEvent", true));
061: }
062:
063: // TODO StepEvent
064: // TODO ThreadEndEvent
065: // TODO ThreadStartEvent
066: // TODO VMDeathEvent
067:
068: }
069:
070: /**
071: * Make sure the test leaves the VM in the same state it found it.
072: */
073: public void localTearDown() {
074: // Ensure that the modification of the "fBool" field has completed
075: fVM.resume();
076: waitUntilReady();
077:
078: // Remove the requests
079: fVM.eventRequestManager().deleteEventRequests(
080: new LinkedList(fAllEvents.keySet()));
081:
082: // Set the value of the "fBool" field back to its original value
083: resetField();
084: }
085:
086: /**
087: * Run all tests and output to standard output.
088: * @param args
089: */
090: public static void main(java.lang.String[] args) {
091: new EventTest().runSuite(args);
092: }
093:
094: /**
095: * Gets the name of the test case.
096: * @see junit.framework.TestCase#getName()
097: */
098: public String getName() {
099: return "com.sun.jdi.event.Event";
100: }
101:
102: /**
103: * Test JDI request().
104: */
105: public void testJDIRequest() {
106: Iterator iterator = fAllEvents.keySet().iterator();
107: while (iterator.hasNext()) {
108: EventRequest request = (EventRequest) iterator.next();
109: Event event = (Event) fAllEvents.get(request);
110:
111: assertEquals(event.toString(), request, event.request());
112: }
113: }
114: }
|