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.ArrayList;
013:
014: import com.sun.jdi.BooleanValue;
015: import com.sun.jdi.StringReference;
016: import com.sun.jdi.event.AccessWatchpointEvent;
017: import com.sun.jdi.event.ModificationWatchpointEvent;
018: import com.sun.jdi.event.WatchpointEvent;
019: import com.sun.jdi.request.EventRequestManager;
020:
021: /**
022: * Tests for JDI com.sun.jdi.event.WatchpointEvent.
023: */
024: public class WatchpointEventTest extends AbstractJDITest {
025:
026: private WatchpointEvent fAccessWatchpointEvent,
027: fStaticAccessWatchpointEvent, fModificationWatchpointEvent;
028:
029: // NB: Static modification watchpoint event is tested in ModificationWatchpointTest
030: /**
031: * Creates a new test.
032: */
033: public WatchpointEventTest() {
034: super ();
035: }
036:
037: /**
038: * Init the fields that are used by this test only.
039: */
040: public void localSetUp() {
041: // Trigger an access watchpoint event
042: fAccessWatchpointEvent = (AccessWatchpointEvent) triggerAndWait(
043: getAccessWatchpointRequest(), "AccessWatchpointEvent",
044: true);
045: assertTrue("Got access watchpoint event",
046: fAccessWatchpointEvent != null);
047:
048: // Trigger a static access watchpoint event
049: fStaticAccessWatchpointEvent = (AccessWatchpointEvent) triggerAndWait(
050: getStaticAccessWatchpointRequest(),
051: "StaticAccessWatchpointEvent", true);
052: assertTrue("Got static access watchpoint event",
053: fStaticAccessWatchpointEvent != null);
054:
055: // Trigger a modification watchpoint event
056: fModificationWatchpointEvent = (ModificationWatchpointEvent) triggerAndWait(
057: getModificationWatchpointRequest(),
058: "ModificationWatchpointEvent", false);
059: // Interrupt the VM so that we can test valueCurrent()
060: assertTrue("Got modification watchpoint event",
061: fModificationWatchpointEvent != null);
062:
063: }
064:
065: /**
066: * Make sure the test leaves the VM in the same state it found it.
067: */
068: public void localTearDown() {
069: // Ensure that the modification of the "fBool" field has completed
070: fVM.resume();
071: waitUntilReady();
072:
073: // Delete the event requests we created in this test
074: EventRequestManager requestManager = fVM.eventRequestManager();
075: requestManager.deleteEventRequests(new ArrayList(requestManager
076: .accessWatchpointRequests()));
077: requestManager.deleteEventRequests(new ArrayList(requestManager
078: .modificationWatchpointRequests()));
079:
080: // Set the value of the "fBool" field back to its original value
081: resetField();
082: }
083:
084: /**
085: * Run all tests and output to standard output.
086: * @param args
087: */
088: public static void main(java.lang.String[] args) {
089: new WatchpointEventTest().runSuite(args);
090: }
091:
092: /**
093: * Gets the name of the test case.
094: * @see junit.framework.TestCase#getName()
095: */
096: public String getName() {
097: return "com.sun.jdi.event.WatchpointEvent";
098: }
099:
100: /**
101: * Test JDI field().
102: */
103: public void testJDIField() {
104: assertEquals("1", getField("fBool"), fAccessWatchpointEvent
105: .field());
106: assertEquals("2", getField("fString"),
107: fStaticAccessWatchpointEvent.field());
108: assertEquals("3", getField("fBool"),
109: fModificationWatchpointEvent.field());
110: }
111:
112: /**
113: * Test JDI object().
114: */
115: public void testJDIObject() {
116: assertEquals("1", getObjectReference(), fAccessWatchpointEvent
117: .object());
118: assertTrue("2", fStaticAccessWatchpointEvent.object() == null);
119: assertEquals("3", getObjectReference(),
120: fModificationWatchpointEvent.object());
121: }
122:
123: /**
124: * Test JDI valueCurrent().
125: */
126: public void testJDIValueCurrent() {
127: assertTrue("1", false == ((BooleanValue) fAccessWatchpointEvent
128: .valueCurrent()).value());
129:
130: assertEquals("2", "Hello World",
131: ((StringReference) fStaticAccessWatchpointEvent
132: .valueCurrent()).value());
133:
134: assertTrue("3",
135: false == ((BooleanValue) fModificationWatchpointEvent
136: .valueCurrent()).value());
137: }
138: }
|