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 com.sun.jdi.event.ClassPrepareEvent;
013: import com.sun.jdi.request.ClassPrepareRequest;
014: import com.sun.jdi.request.EventRequestManager;
015:
016: /**
017: * Tests for JDI com.sun.jdi.request.ClassPrepareRequest.
018: */
019: public class ClassPrepareRequestTest extends AbstractJDITest {
020: /**
021: * Creates a new test.
022: */
023: public ClassPrepareRequestTest() {
024: super ();
025: }
026:
027: /**
028: * Init the fields that are used by this test only.
029: */
030: public void localSetUp() {
031: }
032:
033: /**
034: * Run all tests and output to standard output.
035: * @param args
036: */
037: public static void main(String[] args) {
038: new ClassPrepareRequestTest().runSuite(args);
039: }
040:
041: /**
042: * Gets the name of the test case.
043: * @see junit.framework.TestCase#getName()
044: */
045: public String getName() {
046: return "com.sun.jdi.request.ClassPrepareRequest";
047: }
048:
049: /**
050: * Test JDI addClassFilter(String).
051: */
052: public void testJDIAddClassFilterString() {
053: EventRequestManager requestManager = fVM.eventRequestManager();
054:
055: // Filter is "org.eclipse.debug.jdi.tests.program.*" and loads org.eclipse.debug.jdi.tests.program.TestClass1
056: ClassPrepareRequest request = requestManager
057: .createClassPrepareRequest();
058: request.addClassFilter("org.eclipse.debug.jdi.tests.program.*");
059: ClassPrepareEvent event = (ClassPrepareEvent) triggerAndWait(
060: request, "ClassPrepareEvent1", true, 5000);
061: assertTrue("1", event != null);
062: assertEquals("2",
063: "org.eclipse.debug.jdi.tests.program.TestClass1", event
064: .referenceType().name());
065: requestManager.deleteEventRequest(request);
066:
067: // Filter is "bogus.*" and loads org.eclipse.debug.jdi.tests.program.TestClass2
068: request = requestManager.createClassPrepareRequest();
069: request.addClassFilter("bogus.*");
070: event = (ClassPrepareEvent) triggerAndWait(request,
071: "ClassPrepareEvent2", true, 5000);
072: assertTrue("3", event == null);
073: requestManager.deleteEventRequest(request);
074:
075: // Filter is "*.TestClass3" and loads org.eclipse.debug.jdi.tests.program.TestClass3
076: request = requestManager.createClassPrepareRequest();
077: request.addClassFilter("*.TestClass3");
078: event = (ClassPrepareEvent) triggerAndWait(request,
079: "ClassPrepareEvent3", true, 5000);
080: assertTrue("4", event != null);
081: assertEquals("5",
082: "org.eclipse.debug.jdi.tests.program.TestClass3", event
083: .referenceType().name());
084: requestManager.deleteEventRequest(request);
085:
086: // Filter is "*.eclipse.*.jdi.tests.*4" and loads org.eclipse.debug.jdi.tests.program.TestClass4
087: request = requestManager.createClassPrepareRequest();
088: request.addClassFilter("*.eclipse.*.jdi.tests.program.*4");
089: event = (ClassPrepareEvent) triggerAndWait(request,
090: "ClassPrepareEvent4", true, 5000);
091: assertTrue("6", event == null);
092: requestManager.deleteEventRequest(request);
093:
094: // Filter is "*.eclipse.debug.jdi.tests.program.*" and loads org.eclipse.debug.jdi.tests.program.TestClass5
095: request = requestManager.createClassPrepareRequest();
096: request.addClassFilter("*.eclipse.debug.jdi.tests.program.*");
097: event = (ClassPrepareEvent) triggerAndWait(request,
098: "ClassPrepareEvent5", true, 5000);
099: assertTrue("7", event == null);
100: requestManager.deleteEventRequest(request);
101:
102: // Filter is "org.eclipse.debug.jdi.tests.program.TestClass6" and loads org.eclipse.debug.jdi.tests.program.TestClass6
103: request = requestManager.createClassPrepareRequest();
104: request
105: .addClassFilter("org.eclipse.debug.jdi.tests.program.TestClass6");
106: event = (ClassPrepareEvent) triggerAndWait(request,
107: "ClassPrepareEvent6", true, 5000);
108: assertTrue("8", event != null);
109: assertEquals("9",
110: "org.eclipse.debug.jdi.tests.program.TestClass6", event
111: .referenceType().name());
112: requestManager.deleteEventRequest(request);
113: }
114:
115: /**
116: * Test JDI addClassExclusionFilter(String).
117: */
118: public void testJDIAddClassExclusionFilterString() {
119: EventRequestManager requestManager = fVM.eventRequestManager();
120:
121: // Filter is "org.eclipse.debug.jdi.tests.program.TestClass*" and loads org.eclipse.debug.jdi.tests.program.TestClass7 and org.eclipse.debug.jdi.tests.program.TestClazz8.
122: ClassPrepareRequest request = requestManager
123: .createClassPrepareRequest();
124: request
125: .addClassExclusionFilter("org.eclipse.debug.jdi.tests.program.TestClass*");
126: ClassPrepareEvent event = (ClassPrepareEvent) triggerAndWait(
127: request, "ClassPrepareEvent7", true, 5000);
128: assertTrue("1", event != null);
129: assertEquals("2",
130: "org.eclipse.debug.jdi.tests.program.TestClazz8", event
131: .referenceType().name());
132: requestManager.deleteEventRequest(request);
133:
134: // Filter is "org.eclipse.debug.jdi.tests.program.TestClazz9" and loads org.eclipse.debug.jdi.tests.program.TestClazz9 and org.eclipse.debug.jdi.tests.program.TestClazz10.
135: request = requestManager.createClassPrepareRequest();
136: request
137: .addClassExclusionFilter("org.eclipse.debug.jdi.tests.program.TestClazz9");
138: event = (ClassPrepareEvent) triggerAndWait(request,
139: "ClassPrepareEvent8", true, 5000);
140: assertTrue("3", event != null);
141: assertEquals("4",
142: "org.eclipse.debug.jdi.tests.program.TestClazz10",
143: event.referenceType().name());
144: requestManager.deleteEventRequest(request);
145:
146: }
147: }
|