Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f4ab86ae473c536147d8426659a1e698572908e9 (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
/*******************************************************************************
 * Copyright (c) 2010, 2011 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.jdt.debug.tests.variables;

import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.debug.core.IJavaDebugTarget;
import org.eclipse.jdt.debug.core.IJavaStackFrame;
import org.eclipse.jdt.debug.core.IJavaThread;
import org.eclipse.jdt.debug.eval.EvaluationManager;
import org.eclipse.jdt.debug.eval.IAstEvaluationEngine;
import org.eclipse.jdt.debug.eval.IEvaluationListener;
import org.eclipse.jdt.debug.eval.IEvaluationResult;
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
import org.eclipse.jdt.debug.tests.TestAgainException;

/**
 * Tests that arrays can be accessed with *big* Integers
 */
public class TestIntegerAccessUnboxing15 extends AbstractDebugTest {

	public TestIntegerAccessUnboxing15(String name) {
		super(name);
	}
	
	class Listener implements IEvaluationListener {
		
		private Object lock = new Object();
		private IEvaluationResult result;

		/* (non-Javadoc)
		 * @see org.eclipse.jdt.debug.eval.IEvaluationListener#evaluationComplete(org.eclipse.jdt.debug.eval.IEvaluationResult)
		 */
		public void evaluationComplete(IEvaluationResult result) {
			synchronized (lock) {
				this.result = result;
				lock.notifyAll();
			}
		}
		
		IEvaluationResult getResult() throws Exception {
			synchronized (lock) {
				if (result == null) {
					lock.wait(DEFAULT_TIMEOUT);
				}
			}
			if(result == null) {
				throw new TestAgainException("Retest - evaluation did not complete");
			}
			return result;
		}
		
	}
	
	public void doAccessTest(String snippet, int expected) throws Exception {
		IJavaThread thread= null;
		IAstEvaluationEngine engine = null;
		String typeName = "a.b.c.IntegerAccess";
		createLineBreakpoint(get15Project().findType(typeName), 24);
		try {
			thread= launchToBreakpoint(get15Project(), typeName);
			assertNotNull("Breakpoint not hit within timeout period", thread);
			
			IBreakpoint hit = getBreakpoint(thread);
			assertNotNull("suspended, but not by breakpoint", hit);
			IJavaDebugTarget target = (IJavaDebugTarget) thread.getDebugTarget();
			
			IJavaStackFrame frame = (IJavaStackFrame) thread.getTopStackFrame();
			engine = EvaluationManager.newAstEvaluationEngine(get15Project(), target);
			Listener listener = new Listener();
			engine.evaluate(snippet, frame, listener, DebugEvent.EVALUATION, false);
			IEvaluationResult result = listener.getResult();
			assertFalse("Should be no errors in evaluation", result.hasErrors());
			assertEquals(target.newValue(expected), result.getValue());
		} finally {
			if (engine != null) {
				engine.dispose();
			}
			terminateAndRemove(thread);
			removeAllBreakpoints();
		}
	}	
	
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.debug.tests.AbstractDebugTest#getProjectContext()
	 */
	@Override
	protected IJavaProject getProjectContext() {
		return get15Project();
	}
	
	/**
	 * Test a row can be accessed
	 * 
	 * @throws Exception
	 */
	public void testRowAccess() throws Exception {
		doAccessTest("matrix[new Integer(0)][0]", 1);
	}
	
	/**
	 * Test a column can be accessed.
	 * 
	 * @throws Exception
	 */
	public void testColumnAccess() throws Exception {
		doAccessTest("matrix[2][new Integer(2)]", 9);
	}

	public void testRowColumnAccess() throws Exception {
		doAccessTest("matrix[1][new Integer(1)]", 5);
	}
}

Back to the top