Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 293942e78b0407d73f91dd217a3cb432f7391d46 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*******************************************************************************
 * Copyright (c) 2000, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.jdi.tests;

import java.util.ArrayList;

import com.sun.jdi.BooleanValue;
import com.sun.jdi.StringReference;
import com.sun.jdi.event.AccessWatchpointEvent;
import com.sun.jdi.event.ModificationWatchpointEvent;
import com.sun.jdi.event.WatchpointEvent;
import com.sun.jdi.request.EventRequestManager;

/**
 * Tests for JDI com.sun.jdi.event.WatchpointEvent.
 */
public class WatchpointEventTest extends AbstractJDITest {

	private WatchpointEvent fAccessWatchpointEvent,
		fStaticAccessWatchpointEvent,
		fModificationWatchpointEvent;
	// NB: Static modification watchpoint event is tested in ModificationWatchpointTest
	/**
	 * Creates a new test.
	 */
	public WatchpointEventTest() {
		super();
	}
	/**
	 * Init the fields that are used by this test only.
	 */
	@Override
	public void localSetUp() {
		// Trigger an access watchpoint event
		fAccessWatchpointEvent =
			(AccessWatchpointEvent) triggerAndWait(getAccessWatchpointRequest(),
				"AccessWatchpointEvent",
				true);
		assertTrue("Got access watchpoint event", fAccessWatchpointEvent != null);

		// Trigger a static access watchpoint event
		fStaticAccessWatchpointEvent =
			(AccessWatchpointEvent) triggerAndWait(
				getStaticAccessWatchpointRequest(),
				"StaticAccessWatchpointEvent",
				true);
		assertTrue(
			"Got static access watchpoint event",
			fStaticAccessWatchpointEvent != null);

		// Trigger a modification watchpoint event
		fModificationWatchpointEvent =
			(ModificationWatchpointEvent) triggerAndWait(
				getModificationWatchpointRequest(),
				"ModificationWatchpointEvent",
				false);
		// Interrupt the VM so that we can test valueCurrent()
		assertTrue(
			"Got modification watchpoint event",
			fModificationWatchpointEvent != null);

	}
	/**
	 * Make sure the test leaves the VM in the same state it found it.
	 */
	@Override
	public void localTearDown() {
		// Ensure that the modification of the "fBool" field has completed
		fVM.resume();
		waitUntilReady();

		// Delete the event requests we created in this test
		EventRequestManager requestManager = fVM.eventRequestManager();
		requestManager.deleteEventRequests(
			new ArrayList(requestManager.accessWatchpointRequests()));
		requestManager.deleteEventRequests(
			new ArrayList(requestManager.modificationWatchpointRequests()));

		// Set the value of the "fBool" field back to its original value
		resetField();
	}
	/**
	 * Run all tests and output to standard output.
	 * @param args
	 */
	public static void main(java.lang.String[] args) {
		new WatchpointEventTest().runSuite(args);
	}
	/**
	 * Gets the name of the test case.
	 * @see junit.framework.TestCase#getName()
	 */
	@Override
	public String getName() {
		return "com.sun.jdi.event.WatchpointEvent";
	}
	/**
	 * Test JDI field().
	 */
	public void testJDIField() {
		assertEquals("1", getField("fBool"), fAccessWatchpointEvent.field());
		assertEquals(
			"2",
			getField("fString"),
			fStaticAccessWatchpointEvent.field());
		assertEquals(
			"3",
			getField("fBool"),
			fModificationWatchpointEvent.field());
	}
	/**
	 * Test JDI object().
	 */
	public void testJDIObject() {
		assertEquals(
			"1",
			getObjectReference(),
			fAccessWatchpointEvent.object());
		assertTrue("2", fStaticAccessWatchpointEvent.object() == null);
		assertEquals(
			"3",
			getObjectReference(),
			fModificationWatchpointEvent.object());
	}
	/**
	 * Test JDI valueCurrent().
	 */
	public void testJDIValueCurrent() {
		assertTrue(
			"1",
			false
				== ((BooleanValue) fAccessWatchpointEvent.valueCurrent()).value());

		assertEquals(
			"2",
			"Hello World",
			((StringReference) fStaticAccessWatchpointEvent.valueCurrent())
				.value());

		assertTrue(
			"3",
			false
				== ((BooleanValue) fModificationWatchpointEvent.valueCurrent())
					.value());
	}
}

Back to the top