Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5fc9afaca1b58c28dedd27139f2e5c69280c5ad4 (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
/*******************************************************************************
 * Copyright (c) 2004, 2006 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 com.sun.jdi.AbsentInformationException;
import com.sun.jdi.ClassNotLoadedException;
import com.sun.jdi.IncompatibleThreadStateException;
import com.sun.jdi.InvalidTypeException;
import com.sun.jdi.LocalVariable;
import com.sun.jdi.Location;
import com.sun.jdi.Method;
import com.sun.jdi.StringReference;
import com.sun.jdi.ThreadReference;
import com.sun.jdi.Value;
import com.sun.jdi.event.BreakpointEvent;
import com.sun.jdi.request.BreakpointRequest;
import com.sun.jdi.request.EventRequest;

 /**
  * Test cases for the implementation of providing argumebnt information even if 
  * no debugging information is present in the new java 1.6 VM
  * 
  * @since 3.3
  */
public class ForceEarlyReturnTests extends AbstractJDITest {
	
	/** setup test info locally **/
	@Override
	public void localSetUp() {}

	/**
	 * test to see if forcing early return is supported or not
	 */
	public void testCanForceEarlyReturn() {
		if(fVM.version().indexOf("1.6") > -1) {
			assertTrue("Should have force early return capabilities", fVM.canForceEarlyReturn());
		}
		else {
			assertFalse("Should not have force early return capabilities", fVM.canForceEarlyReturn());
		}
	}
	
	/**
	 * test for the specifying the return type for a forced return to make sure the new return value works
	 */
	public void testForceEarlyReturnIntType() {
		if(!fVM.canForceEarlyReturn()) {
			return;
		}
		try {
			Method method = getMethod("foo", "()Ljava/lang/String;");
			BreakpointRequest br = getBreakpointRequest(method.location());
			br.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
			br.enable();
			EventWaiter waiter = new EventWaiter(br, true);
			fEventReader.addEventListener(waiter);
			triggerEvent("forcereturn2");
			BreakpointEvent bpe = (BreakpointEvent) waiter.waitEvent(10000);
			ThreadReference tref = bpe.thread();
			fEventReader.removeEventListener(waiter);
			if(tref.isSuspended()) {
				if(tref.isAtBreakpoint()) {
					method = getMethod("printNumber", "(Ljava/io/OutputStream;I)I");
					br = getBreakpointRequest((Location) method.locationsOfLine(136).get(0));
					br.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
					br.enable();
					waiter = new EventWaiter(br, true);
					fEventReader.addEventListener(waiter);
					tref.forceEarlyReturn(fVM.mirrorOf("bar"));
					tref.resume();
					bpe = (BreakpointEvent) waiter.waitEvent(10000);
					tref = bpe.thread();
					LocalVariable lv = (LocalVariable)tref.frame(0).visibleVariables().get(2);
					Value val = tref.frame(0).getValue(lv);
					System.out.println(val);
					assertTrue("value should be a StringReference", val instanceof StringReference);
					fEventReader.removeEventListener(waiter);
					//TODO make sure this works with the newest versions of the 1.6VM
					assertTrue("values should be 'foobar'", ((StringReference)val).value().equals("foobar"));
				}
			}
		} catch (IncompatibleThreadStateException e) {
			e.printStackTrace();
		} catch (InvalidTypeException e) {
			e.printStackTrace();
		} catch (ClassNotLoadedException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (AbsentInformationException e) {
			e.printStackTrace();
		}
	}
	
}

Back to the top