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:
015: import com.sun.jdi.request.EventRequest;
016: import com.sun.jdi.request.StepRequest;
017:
018: /**
019: * Tests for JDI com.sun.jdi.request.EventRequest.
020: */
021: public class EventRequestTest extends AbstractJDITest {
022:
023: private List fRequests = new LinkedList();
024:
025: /**
026: * Creates a new test.
027: */
028: public EventRequestTest() {
029: super ();
030: }
031:
032: /**
033: * Init the fields that are used by this test only.
034: */
035: public void localSetUp() {
036: // Get all kinds of request
037: if (fVM.canWatchFieldAccess())
038: fRequests.add(getAccessWatchpointRequest());
039: fRequests.add(getBreakpointRequest());
040: fRequests.add(fVM.eventRequestManager()
041: .createClassPrepareRequest());
042: fRequests.add(fVM.eventRequestManager()
043: .createClassUnloadRequest());
044: fRequests.add(getExceptionRequest());
045: if (fVM.canWatchFieldModification())
046: fRequests.add(getModificationWatchpointRequest());
047: fRequests.add(fVM.eventRequestManager().createStepRequest(
048: getThread(), StepRequest.STEP_LINE,
049: StepRequest.STEP_OVER));
050: fRequests.add(fVM.eventRequestManager()
051: .createThreadDeathRequest());
052: fRequests.add(fVM.eventRequestManager()
053: .createThreadStartRequest());
054: }
055:
056: /**
057: * Make sure the test leaves the VM in the same state it found it.
058: */
059: public void localTearDown() {
060: // Delete the requests we created in this test
061: fVM.eventRequestManager().deleteEventRequests(fRequests);
062: }
063:
064: /**
065: * Run all tests and output to standard output.
066: * @param args
067: */
068: public static void main(java.lang.String[] args) {
069: new EventRequestTest().runSuite(args);
070: }
071:
072: /**
073: * Gets the name of the test case.
074: * @see junit.framework.TestCase#getName()
075: */
076: public String getName() {
077: return "com.sun.jdi.request.EventRequest";
078: }
079:
080: /**
081: * Test JDI disable(), enable(), isEnable() and setEnable(boolean).
082: */
083: public void testJDIEnable() {
084: for (int i = 0; i < fRequests.size(); i++) {
085: EventRequest request = (EventRequest) fRequests.get(i);
086: assertTrue("1." + i, !request.isEnabled());
087: request.setEnabled(true);
088: assertTrue("2." + i, request.isEnabled());
089: request.setEnabled(false);
090: assertTrue("3." + i, !request.isEnabled());
091: request.enable();
092: assertTrue("4." + i, request.isEnabled());
093: request.disable();
094: assertTrue("5." + i, !request.isEnabled());
095: }
096: }
097:
098: /**
099: * Test JDI setSuspendPolicy(int) and suspendPolicy().
100: */
101: public void testJDISuspendPolicy() {
102: int policy = EventRequest.SUSPEND_EVENT_THREAD;
103: for (int i = 0; i < fRequests.size(); i++) {
104: EventRequest request = (EventRequest) fRequests.get(i);
105: request.setSuspendPolicy(policy);
106: }
107: for (int i = 0; i < fRequests.size(); i++) {
108: EventRequest request = (EventRequest) fRequests.get(i);
109: assertTrue(String.valueOf(i),
110: request.suspendPolicy() == policy);
111: }
112: }
113:
114: /**
115: * Test JDI putProperty and getProperty.
116: */
117: public void testJDIProperties() {
118: EventRequest request = (EventRequest) fRequests.get(0);
119: request.putProperty(new Integer(0), "prop1");
120: String prop = (String) request.getProperty(new Integer(0));
121: assertTrue("1", prop.equals("prop1"));
122:
123: request.putProperty(new Integer(0), null);
124: prop = (String) request.getProperty(new Integer(0));
125: assertTrue("2", prop == null);
126:
127: request.putProperty(new Integer(0), "prop2");
128: request.putProperty(new Integer(0), "prop3");
129: prop = (String) request.getProperty(new Integer(0));
130: assertTrue("3", prop.equals("prop3"));
131:
132: request.putProperty(new Integer(0), null);
133: prop = (String) request.getProperty(new Integer(0));
134: assertTrue("4", prop == null);
135:
136: request.putProperty(new Integer(1), null);
137: prop = (String) request.getProperty(new Integer(1));
138: assertTrue("5", prop == null);
139:
140: request.putProperty(new Integer(1), "prop1");
141: prop = (String) request.getProperty(new Integer(1));
142: assertTrue("6", prop.equals("prop1"));
143:
144: }
145: }
|