Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: df0003e3d5f3bde97f5eb84b938cdc8b33c31ed7 (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*******************************************************************************
 * 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.LinkedList;
import java.util.List;
import java.util.Map;

import com.sun.jdi.AbsentInformationException;
import com.sun.jdi.ClassNotLoadedException;
import com.sun.jdi.InvalidTypeException;
import com.sun.jdi.LocalVariable;
import com.sun.jdi.ObjectReference;
import com.sun.jdi.ReferenceType;
import com.sun.jdi.StackFrame;
import com.sun.jdi.ThreadReference;

/**
 * Tests for JDI com.sun.jdi.StackFrame.
 */
public class StackFrameTest extends AbstractJDITest {

	private StackFrame fFrame;
	/**
	 * Creates a new test.
	 */
	public StackFrameTest() {
		super();
	}
	/**
	 * Init the fields that are used by this test only.
	 */
	@Override
	public void localSetUp() {
		// Get the frame running MainClass.run()
		fFrame = getFrame(RUN_FRAME_OFFSET);

	}
	/**
	 * Run all tests and output to standard output.
	 * @param args
	 */
	public static void main(java.lang.String[] args) {
		new StackFrameTest().runSuite(args);
	}
	/**
	 * Gets the name of the test case.
	 * @see junit.framework.TestCase#getName()
	 */
	@Override
	public String getName() {
		return "com.sun.jdi.StackFrame";
	}
	/**
	 * Test JDI equals() and hashCode().
	 */
	public void testJDIEquality() {
		StackFrame sameFrame = getFrame(RUN_FRAME_OFFSET);
		StackFrame otherFrame = getFrame(0);

		// Not identical
		assertTrue("1", fFrame != sameFrame);
		// But equal
		assertTrue("2", fFrame.equals(sameFrame));
		assertTrue("3", fFrame.hashCode() == sameFrame.hashCode());

		assertTrue("4", fFrame.equals(fFrame));
		assertTrue("5", fFrame.hashCode() == fFrame.hashCode());

		assertTrue("6", !fFrame.equals(otherFrame));

		assertTrue("7", !fFrame.equals(new Object()));
		assertTrue("8", !fFrame.equals(null));
	}
	/**
	 * Test JDI location().
	 */
	public void testJDILocation() {
		assertNotNull("1", fFrame.location());
	}
	/**
	 * Test JDI setValue(LocalVariable, Value), getValue(LocalVariable) and
	 * getValues(List).
	 */
	public void testJDISetGetValue() {
		// setValue
		ThreadReference thread = (ThreadReference) fVM.allThreads().get(0);
		LocalVariable var = getLocalVariable();
		try {
			fFrame.setValue(var, thread);
		} catch (ClassNotLoadedException e) {
			assertTrue("1.1", false);
		} catch (InvalidTypeException e) {
			assertTrue("1.2", false);
		}

		// getValue(LocalVariable)
		ThreadReference value =
			(ThreadReference) fFrame.getValue(getLocalVariable());
		assertEquals("2", thread, value);

		// getValues(List)
		List vars = new LinkedList();
		vars.add(var);
		Map values = fFrame.getValues(vars);
		value = (ThreadReference) values.get(var);
		assertEquals("3", thread, value);

		// test null value
		var = getLocalVariable();
		try {
			fFrame.setValue(var, null);
		} catch (ClassNotLoadedException e) {
			assertTrue("4.1", false);
		} catch (InvalidTypeException e) {
			assertTrue("4.2", false);
		}

		value = (ThreadReference) fFrame.getValue(getLocalVariable());
		assertEquals("5", null, value);

	}
	/**
	 * Test JDI thisObject().
	 */
	public void testJDIThisObject() {
		ObjectReference object = fFrame.thisObject();
		ReferenceType expected = getMainClass();
		ReferenceType referenceType = object.referenceType();
		assertEquals("1", expected, referenceType);
	}
	/**
	 * Test JDI thread().
	 */
	public void testJDIThread() {
		assertEquals("1", getThread(), fFrame.thread());
	}
	/**
	 * Test JDI visibleVariableByName(String).
	 */
	public void testJDIVisibleVariableByName() {
		LocalVariable var = null;
		try {
			var = fFrame.visibleVariableByName("t");
		} catch (AbsentInformationException e) {
			assertTrue("1", false);
		}
		assertEquals("2", getLocalVariable(), var);
		try {
			var = fFrame.visibleVariableByName("bogus");
		} catch (AbsentInformationException e) {
			assertTrue("3", false);
		}
		assertTrue("4", null == var);
	}
	/**
	 * Test JDI visibleVariables().
	 */
	public void testJDIVisibleVariables() {
		List vars = null;
		try {
			vars = fFrame.visibleVariables();
		} catch (AbsentInformationException e) {
			assertTrue("1", false);
		}
		assertEquals("2", 2, vars.size());

		LocalVariable var;
		int i = 0;
		do {
			var = (LocalVariable) vars.get(i++);
		} while (!var.name().equals("t"));
		assertEquals("3", getLocalVariable(), var);
	}
}

Back to the top